How to check if a Mix task exists?

Hey everyone,

I am automating the setup of an Elixir project and for this project, I want to install the Phoenix project generator (phx_new | Hex) so other developers don’t have to think about this. Is there a way to check if a specific Mix task is present? Normally, I check if a command exists with command -v my_command_123 || install my_command_123, but this doesn’t work in this situation.

Someone has an idea?

Yup you can use ASDF!!

brew install asdf
asdf plugin-add elixir GitHub - asdf-vm/asdf-elixir: Elixir plugin for asdf version manager
asdf plugin-add erlang GitHub - asdf-vm/asdf-erlang: Erlang plugin for asdf version manager

asdf install

mix do local.hex, local.phx, local.rebar
asdf reshim elixir

And keep a .tool-versions file
elixir 1.14.0-otp-25
erlang 25.1.1


But if you want true control, you should use Ansible


P.S. I use Taskfile, similar to a makefile and keep all the initialisation option in one place. It’s better not to automate everything.

Also your developers should know these things, don’t abstract out everything, else down the line it will get too complicated to maintain. And instead of a simple command to install a simple archive, others have to learn and debug another tool.

mix archive lists all installed archives, but I’m not sure that’ll be too useful for scripting as it’s meant for human consumption.

1 Like
$ mix help | grep phx.new
mix phx.new                                # Creates a new Phoenix v1.7.0-rc.0 application
mix phx.new.ecto                           # Creates a new Ecto project within an umbrella project
mix phx.new.web                            # Creates a new Phoenix web project within an umbrella project

Can also be used to check the existence of a mix task. mix help lists all available mix commands…

I’d prefer to have them setup via docker-compose in most of the cases unless you need wallaby testing using GUI…