Create an alias for another task in mix.exs?


So I am using this library from @lpil which I really like.

Usually I just run mix and I let the process running.

As a bonus to this library, you can also execute it by passing the --only flag. For example, if I want to watch only my “super_duper_tests” I can do it like this: mix --only super_duper_tests and this will only watch all the tests that have, for example, the @moduletag :super_duper_tests on them.

Enter Alias

So, this is all fun, but I am lazy and I don’t like typing. So I want to create an alias like this:

mix that will be translated to mix --only super_duper_tests.

To achieve this I tried the following on my mix.exs file:

defp aliases do
    "": [" --only super_duper_tests"]


You may have guessed, since I am posting here, that this is not working. When I try my new alias, I get the error message Could not find task.

So obviously I am doing something wrong in the configuration.


How can I create an alias for mix

How did you defined the dependency? Are you running in correct Mix environment?

1 Like

This is how I defined it:

[{:mix_test_watch, "~> 1.0", only: :dev}]

Perhaps it should be:

[{:mix_test_watch, "~> 1.0", only: [:dev, :test]}]



Yep, it needed to be [{:mix_test_watch, "~> 1.0", only: [:dev, :test]}].

1 Like

BTW I prefer to use entr or watchman with mix test --listen-on-stdin


You mean:

I couldn’t find any github repo for entr, could you post a link?

I personally use watchexec:

watchexec -e 'ex,exs,eex,leex' -- 'mix format && mix test --stale'


Blog post showing usage of entr

1 Like