Cannot run tests in a mix umbrella project's child app alone due to in_umbrella dependency


I have an umbrella project who’s structure looks like this:

  - app1
  - app2
  - app3

app2 and app3 both have app1 as a dependency, marking them with in_umbrella: true.

When I cd to apps/app2 and run mix test or mix cmd --app app2 mix test from the umbrella root, I see the following error:

warning: redefining module App1.MixProject (current version defined in memory)

Error while loading project :app1 at /Users/mpope/application/apps/app1
Error while loading project :app1 at /Users/mpope/application/apps/app1
** (CompileError) /Users/mpope/application/apps/app1/mix.exs:1: cannot define module App1.MixProject because it is currently being defined in /Users/mpope/application/apps/app1/mix.exs:1
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:126: :erl_eval.exprs/5

I have tried to google for this issue and look through the github issue list but I can’t find anything relating to this. I can create a sample app and push it up to github if I am not providing enough context.

Elixir version below:

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

Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)

Thank you very much!

Note, edited the title for clarity.

Note I have tried mix cleaning and have manually wiped the _build/ and deps/ dirs.

Okay, looks like this works to run a single test file:

mix test apps/app2/test/app2_test.exs 

so there is a workaround, but I’m still curious as to why the first set of commands doesn’t work.

Running mix test <filename> at the top level will still boot all the applications in the umbrella, in the same way that running bare mix test at top level does.

The redefinition errors are odd; are your Mixfiles doing anything unusual? Also check that one of them didn’t end up with defmodule App1.MixFile do even though it’s in a different app.

The only thing that’s really unusual is that I alias test to a custom mix task to run some erlang ct tests in App1

The mixfiles are clean in that respect.

If I recall correctly, aliases are shared in an umbrella project so if you define an alias in one child app, that alias is used for all applications in the umbrella (unless you have one defined in the top-level umbrella application). Can you try removing that custom mix task and see if you still get the error/warning?

I removed the alias and the same error occurs, sadly.