简体   繁体   中英

'Task could not be found' for custom mix task

I have a task Thing in lib/mix/tasks/thing.exs

The code is:

defmodule Mix.Tasks.Thing do
  use Mix.Task

  def run(_) do
    IO.puts "hello world"
  end

end

When I run mix thing or mix Thing I get The task thing could not be found or The task Thing could not be found

I've tried running mix compile beforehand, which didn't help.

I also tried putting the code from this question directly into my mix.exs, as shown in that question. I still couldn't run the task.

Mix tasks need to be compiled. If you rename from lib/mix/tasks/thing.exs to lib/mix/tasks/thing.ex then it should work.

You can read more about scripted mode (.exs) at: http://elixir-lang.org/getting-started/modules.html#scripted-mode

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