Umbrella dependency in_umbrella: true causing cycles in the dependency graph

I have been seeing some weird and intermittent errors in my Umbrella applications lately (like Phoenix instrumenters from one umbrella child app trying to info a Phoenix instrumenter from another umbrella child app)

But first thing - shouldn’t this work?

App1 's mix.exs

defp deps do
    [
...
     {:app2, in_umbrella: true},
...
   ]
  end

App2 's mix.exs

defp deps do
    [
...
     {:app1, in_umbrella: true},
...
   ]
  end

It is currently causing ** (Mix) Could not sort dependencies. There are cycles in the dependency graph - even if the the child apps do not have any of the same deps.

OS: macOS 10.14.3

$ elixir -v

Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.8.1 (compiled with Erlang/OTP 21)

No, circular dependency graphs are not supported, you need to break the cycle such that the beam knows which application has to be started first.

3 Likes

The beam starts applications in the order the dependency tree requires and circular dependencies break the ability to do so. App1 would need App2 to be started first, while App2 would need App1 to be started first.

If I remove one dependency, you will get a warning. In my case:
warning: AutobaseWeb.Endpoint.broadcast!/3 defined in application :autobase_web is used by the current application but the current application does not depend on :autobase_web. To fix this, you must do one of:

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

  2. If :autobase_web 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 :autobase_web, you may optionally skip this warning by adding [xref: [exclude: [AutobaseWeb.Endpoint]]] to your “def project” in mix.exs

What should I do? Ignore it?

Indeed, there was an obvious dependency loop!
I eliminated the loop and everything compiled without warnings.