3

I have a dependency that starts an application, but I only want to use its modules and don't want its supervisor running. How do I exclude it from startup?

I have not found anything related to this in mans for app.start, run or in Mix.Project module

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
Ooba Elda
  • 1,622
  • 1
  • 12
  • 18

2 Answers2

7

Specifying runtime is usually the right approach for most applications:

{:some_dep, "~> 1.0.0", runtime: false}

This causes the application supervision tree of the dependency to not get started with the rest of your application. But this still allows you to manually start it during runtime if you desire.

When using app: false instead, the dependency's Application module isn't read at all so you can't even manually start it later.

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
  • Does `runtime: false` not work on umbrella dependencies? I just tried it and received `{:error, {:already_started, :myapp}}` error when i tried to start that app – Ooba Elda Nov 17 '18 at 12:43
  • Also, I can't start the app for `runtime: false` using Distillery release. It says `{:error, {'no such file or directory', 'some_app.app'}}` – Ooba Elda Nov 18 '18 at 04:23
4

Just found it in mix help deps

  • :app - when set to false, does not read the app file for this dependency. By default, the app file is read
  • :runtime - whether the dependency is part of runtime applications. Defaults to true which automatically adds the application to the list of apps that are started automatically and included in releases

Both of them work in my case, not sure what is the difference though.

Ooba Elda
  • 1,622
  • 1
  • 12
  • 18