Include runtime lib without starting dep

Hi, I have mix project myapp that uses another mix project as dep:

  defp deps do
    [
      {:distillery,   "~> 2.1"},
      {:mylib,         path: "../mylib", runtime: false}
    ]
  end

Because mylib itself is a Rest endpoint to CRUD db models, so I don’t want to start it with myap, hence the runtime: false.

Problem: mylib contains modules that to be used in myapp. But with runtime: false option, I get ...module undefined error... when using them. When set runtime: true, everything is fine.

So, how do I not start mylib with myapp but can still use its modules in runtime?

Thanks a lot!

Extract those functions into a library that is used by myapp and mylib, or make mylib configurable to not start its REST endpoint when something in the appenv is “false”.

That should not be required though. I believe runtime: false should behave as you expect.

runtime: false means to not include the dependency into a release, nor does mix add the libraries location to the “search path” of the running application, I think it even explicitely unloads it after compilation phase.

1 Like

Oh then I understood it completely wrong.

Then I guess the solution would be to specify applications instead of extra_applications ? I believe this is configurable (but you would need to write all required applications in there).

No, you really do not want to maintain :applications manually, and doing runtime: false + putting it in :extra_applications is contradictionary.

There is one *_applications option that could help, but I won’t talk about it, as it would lead to wrong usage, as far as I understand that attribute.

The OP is in the position to change the design, instead of having to workaround it. So why propose any workarounds?

Because that seems it should be something very easy to do : I have this dep, I need some code from it but I do not want to start its supervision, as I know the code that I will use will not require some processes to be up. Edit: And now I know, thanks.

That is true though, I agree it is the best solution in the long term.

I was hoping not to create a new project just to run the rest endpoint… But I guess it is the go-to solution then.

Thanks a lot guys!