简体   繁体   English

如何在伞形项目的根目录下创建 Mix 任务?

[英]How to create a Mix task at the root of an umbrella project?

I have an Elixir umbrella project.我有一个Elixir伞形项目。 Each apps in this project can be compiled into executable file using mix escript.build .这个项目中的每个应用程序都可以使用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.由于根目录没有lib目录,我添加了一个并在其中创建了一个混合任务。 But that is not listed in mix help .但这没有列在mix help

How can I define a custom mix task at the root of an umbrella project?如何在伞形项目的根处定义自定义混合任务?

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.如果您想拥有一个在多个应用程序之间共享的任务,您应该像其他任何应用程序一样在伞中的常规应用程序中定义它,并让使用该任务的其他应用程序依赖于它,就像您对任何其他部分所做的一样的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM