3
votes

I have an umbrella project with 3 apps: main_web, main and child.

I have a macro defined in main which the child app uses.

When compiling, I sometimes get an error saying that Main.MyMacro is not defined in some_file_in_child_app.ex when I run the same command again, everything is fine.

I think this is from some_file_in_child_app.ex trying to use the macro before it has been compiled.

What is a good way to go about ensuring Main.MyMacro is loaded and so that I can avoid this error?

I'm not sure if going down the lines of running mix compile apps/main is the right way to go

1

1 Answers

5
votes

If you have dependencies between your umbrella applications, you need to explicitly list them.

You should add this to apps/child/mix.exs:

def deps do
  [
    # ... other deps ...
    {:main, in_umbrella: true}
  ]
end

Now Mix will make sure to compile main before compiling child.