ccavolt
Can't run hex mix tasks in alias
In my mix.exs file, if I try to create an alias with a hex mix task, for example hex.audit or hex.outdated, I get an error saying the task could not be found. I know I have hex installed because the above mix tasks work on the command line, so I’m guessing it has something to do with those mix tasks not being sourced when run as an alias, but I’m unsure how I can fix it. Here’s a larger example:
defp aliases do
[
audit: ["hex.audit"]
]
end
Most Liked
jonatanklosko
You can do this:
def aliases do
[
testtask: [
"deps.get",
"deps.compile",
# Compilation prunes code paths, so Hex task modules are no
# longer available. We need to bring the application back
# explicitly, in order to access its modules.
fn _ -> Mix.ensure_application!(:hex) end,
"hex.audit"
]
]
end
katafrakt
So I traced it down to the fact that after running any non-hex task Code.ensure_loaded(Mix.Tasks.Hex.Audit) returns {:error, :nofile}. But if no other non-hex task was run before, it returns {:module, Mix.Tasks.Hex.Info}. Unfortunately I don’t know why is that, but maybe someone more knowledgeable would have some idea.
ccavolt
Okay, so apparently my example wasn’t specific enough. ![]()
Upon further examination, the hex mix task has to be at least the third in line in the list. The list can have more than three items in it as long as the hex mix task is number one or two. So for example this works:
defp aliases do
[
testtask: ["deps.get", "hex.audit", "deps.compile"]
]
end
But this does not:
defp aliases do
[
testtask: ["deps.get", "deps.compile", "hex.audit"]
]
end
It results in:
** (Mix) The task "hex.audit" could not be found. Did you mean "deps.audit"?








