mix recompile cannot load some dependencies when in umbrella project

Good evening, I created an umbrella project, and write the :amqp dependency on the top mix.exs file. Then some problems occur when I use mix clean and mix compile, here is the detais:

  • Elixir version: Elixir 1.15.7 (compiled with Erlang/OTP 26)

  • Erlang version: Erlang/OTP 26 [erts-14.1.1]

  • OS: Arch Linux x86_64

  • Current Behaviour:

mix new foo --umbrella
cd foo/apps
mix new bar

Then write amqp dependency on the root mix.exs file, and run mix deps.get:

foo/mix.exs

defp deps do
  [
    {:amqp, "~> 3.3"}
  ]
end

Then define an module use AMQP in bar:

foo/apps/bar/lib/bar2.ex

defmodule Bar2 do
  use AMQP
end

The first time run mix compile it succeeded, but when I run mix clean and mix compile after, it will report error:

==> bar
Compiling 2 files (.ex)
error: module AMQP is not loaded and could not be found
lib/bar2.ex:2: Bar2 (module)

== Compilation error in file lib/bar2.ex ==
** (CompileError) lib/bar2.ex: cannot compile module Bar2 (errors have been logged)
(elixir 1.15.7) expanding macro: Kernel.use/1
lib/bar2.ex:2: Bar2 (module)

If I put the amqp dependency on the bar’s mix.exs file there is no such errors. Is this way of writing depencencies on the top mix.exs wrong?

Check that your mix.exs in the bar app has the correct paths. The guide shows what it should look like:

def project do
    [
      app: :kv_server,
      version: "0.1.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.14",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

Thanks for answer. The bar app’s mix.exs file was generated by the mix command, this is the path config:

  def project do
    [
      app: :bar,
      version: "0.1.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.15",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

There shouldn’t be a problem with this file, right?