简体   繁体   中英

Write a Mix task that runs after deps.get

Is there a way to hook into Elixir's Mix built in tasks to execute a task after another one has completed?

I know you can do something similar to this.

defmodule Mix.Tasks.Other.Get
  use Mix.Task

  @shortdoc "Other dependencies?"
  def run(_) do
    Mix.Task.run("deps.get")
  end
end

But I kindof want a task to run right after mix deps.get considering using make to wrap the commands that make the most sense. (ie make deps which would run both mix deps.get then mix other.get )

You can use a Mix alias for that:

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "1.0.0",
      aliases: aliases()
    ]
  end

  defp aliases do
    [
      "deps.get": ["deps.get", "custom.task"]
    ]
  end
end

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