beardedeagle

beardedeagle

Declare an OTP application as a dependency without putting it in application/0?

I have a library I’ve owned for some time, beardedeagle/mnesiac, and over the last few years I’ve noticed several people forking the repo to remove :mnesia from application/0. I figured, if it’s happened more than a couple times, I’d take a look into it and see if that’s something I should change in the library proper.

So, digging into it, I see two potential reasons for why people are doing this:

That last point really resonates with me, as I want consumers to have complete control around the specifics around mnesia start/ownership. I put mnesia into included_applications in an attempt to ensure it was loaded, but not started by my library. However, if I remove mnesia from application/0 in my mix.exs, my test suite will understandably start throwing warnings like the following:

warning: :mnesia.add_table_copy/3 defined in application :mnesia is used by the current application but the current application does not depend on :mnesia. To fix this, you must do one of:

  1. If :mnesia is part of Erlang/Elixir, you must include it under :extra_applications inside “def application” in your mix.exs

  2. If :mnesia is a dependency, make sure it is listed under “def deps” in your mix.exs

  3. In case you don’t want to add a requirement to :mnesia, you may optionally skip this warning by adding [xref: [exclude: [:mnesia]]] to your “def project” in mix.exs

So now I’m trying to figure out the best way to handle this. Here is my understanding of things so far:

  • Keeping mnesia in included_applications doesn’t start mnesia, but the mnesia process itself would be owned by mnesiac as far as I can tell, which I don’t want. Also, this violates the first point above. So, this is out.
  • Putting mnesia into extra_applications with :optional won’t work for what I’m trying to do as the only thing that does is ensure that my library startup won’t be impacted in the event that mnesia isn’t available to start. Also, the goal here is to make it so my library doesn’t start mnesia which as far as I can tell extra_applications will do, so this is out.
  • I could xref: [exclude: [:mnesia]]. I’m not particularly a fan of this as to me, it makes it seem like the library doesn’t need mnesia when it clearly does.

I am unsure there is a better way to handle this than excluding it from xref though. I’m also unsure if doing this via the xref method would have any other potential pitfalls I’m not considering. Any suggestions, pointers or docs would be greatly appreciated here. Thank you in advance.

Most Liked

christhekeele

christhekeele

Would making your application/0 conditional on Mix.env() so that:mnesia is only included for development/testing purposes, but not “prod” package publishing purposes, work? Ex. this example

tristan

tristan

Rebar3 Core Team

Another option may be to keep it in applications but the user setting mnsia to load in their release so they can start it where ever they want.

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

Other popular topics Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement