4

I have an Elixir umbrella project. Each apps in this project can be compiled into executable file using mix escript.build.

I am trying to run this command from the root of umbrella project and got the following error

** (RuntimeError) Trying to access Mix.Project.app_path for an umbrella project but umbrellas have no app

I understand why this won't work. So tried to create a custom mix task at the root of the umbrella project. Since the root don't have a lib directory, I added one and created a mix task inside it. But that is not listed in mix help.

How can I define a custom mix task at the root of an umbrella project?

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
  • This question initially confused me. You talk about running a mix task `escript.build` for each project in the umbrella, and then -- when that doesn't work -- you jump to creating a new mix task. Which means, unfortunately, that José's answer doesn't address my problem. Guess I'll open a new one. – Roger Lipscombe Nov 14 '19 at 16:54
  • I found https://github.com/vic/mix_under, which is stale, but might help with the original question. – Roger Lipscombe Nov 14 '19 at 16:56

1 Answers1

11

Your umbrella projects do not have code. That's because the applications in the umbrella are meant to work regardless if they are inside the umbrella or not. If you want to have a task that is shared across multiple applications, you should define it inside a regular application in the umbrella, like any other, and have the other applications that use the task depend on it, like you would for any other piece of code.

José Valim
  • 50,409
  • 12
  • 130
  • 115
  • Thanks. That makes sense. But now I am missing the whole point of having a `mix.exs` at the root level. I was thinking `deps` added there will get available to all sub-projects. Looks like that is not the case. Why will you need `mix.exs` and `deps` at the root level? – Navaneeth K N Jun 15 '16 at 02:43
  • 2
    You rarely use those. The only use case I can think for deps in the umbrella is for mix tasks you want to run at the umbrella level. – José Valim Jun 15 '16 at 19:51