简体   繁体   中英

Preventing a mix task being included when your project is included as a mix dep

An Elixir library I'm writing has two custom mix tasks, one intended to be used by users who have made my library a dependency of their project, one intended to be used only within my project.

The problem here is that both mix tasks are available to users in their projects after they have added mine as a dep.

How do I prevent this? I tried to avoid the task in package: [ files: [ etc ] ] in my Mix config, but it was still available in my test project that specifies my library as a dep via git.

Currently Mix does not really support the idea of private tasks directly. A couple options are:

  • Define it in your mix.exs (for example, as an alias) or create it inside tasks/my_task.exs and Code.require_file "tasks/my_task.exs" on top of your mix.exs . The second option is not great as you will execute the code that defines a task on every mix command you use

  • Just use a script. Create a scripts directory if you want and then, when you want to run it, just do: mix run scripts/do_x.ex arg1 arg2 arg3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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