How to create a Mix task at the root of an umbrella project?
Asked Answered
G

1

5

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?

Gymnastics answered 14/6, 2016 at 2:42 Comment(2)
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.Camey
I found github.com/vic/mix_under, which is stale, but might help with the original question.Camey
A
12

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.

Abbreviation answered 14/6, 2016 at 6:54 Comment(2)
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?Gymnastics
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.Brescia

© 2022 - 2024 — McMap. All rights reserved.