How to use my own library in a mix config?

During execution of a mix config, it still has no access to the dependencies of a project, right? Then what do I do if I need to utilize my own dependency-library in it? I need to call a few of functions of my own library, that is. And not once and in one project, but throughout multiple projects. That is, simply copying Elixir code into a mix config although would work, wouldn’t be a wise solution.

The question is about using it in dev mode, as well as in production.

You can reference a dependency in mix.exs deps via a git repo, e.g.

{:my_lib, git: "https://github.com/blah/my_lib"}

or by path:

{:shared_stuff, path: "../shared_stuff"},

Docs are here for more info: mix deps — Mix v1.12.0

It is allowed to run application code in runtime.exs file. AFAIK it is available starting from Elixir 1.11

You can also look at Config.Provider — Elixir v1.12.0, which runs at the same time runtime.exs is evaluated.

1 Like

During execution of a mix config, it still has no access to the dependencies of a project, right?

The only way to do so is go to install Mix plugin globally, just like it is done with Hex. Unfortunately there is no other way, been there, tried to talk with the Core Team. Unfortunately the design choices of Mix make it impossible to have something like Rebar3 plugins on per project basis.