11

If I have a mix.exs file something like:

defmodule Mix.Tasks.My_task do
  use Mix.Task

  @shortdoc "Perform my task"

  def run(_) do
    IO.puts "Working"
  end
end

defmodule ElixirKoans.Mixfile do
  use Mix.Project

  def project do

  ...    

end

I can happily run this with mix my_task.

How do I make my_task be the default, so it is executed when I run mix without a task?

Bryan Ash
  • 4,385
  • 3
  • 41
  • 57

1 Answers1

23

It looks like you can define inside the project block (mix.exs) using default_task:

def project do
  [default_task: "run"]
end

More info: https://github.com/elixir-lang/elixir/blob/f3f64cdba205253ca0bbc0ce6a5dddd500ffb48f/lib/mix/lib/mix/project.ex#L266-L280

Eduardo
  • 551
  • 6
  • 15
  • 1
    Thank you for this. I wish I could give you an extra +1 for highlighting the line numbers, I didn't know that was possible. – Bryan Ash Sep 29 '13 at 06:06
  • 1
    Nice! You can select lines on github using click and then shift + click :) – Eduardo Sep 29 '13 at 06:57
  • just in case anyone else had the same problem I did, this should go into mix.exs, not the mix task you have implemented. – jacob Jan 30 '16 at 22:57