Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use compile-only dependencies in Elixir

Tags:

elixir

exrm

When would it be appropriate to specify a dependency only in deps in my mix.exs and not as a runtime dependency in applications?

I thought that applications are actual applications that need to be started before my own application can be started, but I run into a problem where exrm wasn't putting the Jazz library (which I think only contains pure functions) into the release until I included :jazz in applications.

like image 596
Paweł Obrok Avatar asked May 15 '15 11:05

Paweł Obrok


1 Answers

An OTP application is more like a component - a bunch of modules and functions that may (but need not) run some processes. If an OTP app doesn't start its own supervision tree, it is called a library application. Either way, if you use some of libs functions at runtime, you need to specify it as a runtime dep.

In contrast, compile-time dependency only ensures that the 3rd party code is fetched and available locally (on your dev/build machine). This is useful if the 3rd party code does its magic outside of runtime. An example could be my own ExActor or pure Erlang meck mocking library. In the first case ExActor does its magic during compilation, while in the second case you need the mocking library only during tests.

like image 125
sasajuric Avatar answered Oct 15 '22 23:10

sasajuric