Common modules in umbrella app

We started with a monolith application. Now we decided to extract some parts to an umbrella project.

We noticed that we have some common macros used in tests. We think that they can be used in multiple umbrella childs. How do you usually deal with that kind of dependencies? I don’t want to store these macros in multiple umbrella childs.

1 Like

The title of your post already reveals the answer: Factor the Macros out into a dedicated module.

Then you have two options:

  1. Make the module a child app that can be a dependency of your other apps
  2. Manage the module in a separate repository and require that as a test dependency. You could either do that with a git repository or with the newly announced private Hex repositories.

I see option 1 as composed of two different sub-options:

1.1. The child app is a supervision tree application which implements the application behaviour and as such needs to mention a callback module through mix mod.
1.2. The child app is just a library application with no running processes which is used to bundle code together. Thus we won’t add it to a supervision tree and there is nothing to start. You run mix new inside your apps directory to create the app and its brand new mix.exs file is already the good one without mod. Then you might want to add it as a dependency in other child apps using {:myapp, in_umbrella: true}.

I had to use technique 1.2 in a recent project but couldn’t easily find it because I always thought only 1.1 was possible and every answer I looked at was focused on 1.1.

1 Like