Mix Custom Compiler - clean/0 not called

Hi :wave:

I’ve been trying to get a custom compiler going for a library I’m looking at putting together but clean() never seems to be called.

I’m on macOS, Elixir is 1.10.4 and Erlang is OTP 23.

It’s easy enough to reproduce from a fresh mix project:

mix new testc

# lib/mix/tasks/compile.testc.ex
defmodule Mix.Tasks.Compile.Testc do
  use Mix.Task.Compiler

  @impl true
  def run(_args) do
    IO.puts("Compiling...")
    :ok
  end

  @impl true
  def clean do
    IO.puts("Cleaning...")
  end

end
# mix.exs
defmodule Testc.MixProject do
  use Mix.Project

  def project do
    [
      app: :testc,
      version: "0.1.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      compilers: Mix.compilers() ++ [:testc],
      deps: deps()
    ]
  end 

  #...

end

Compiling works as expected.

% mix compile
Compiling 2 files (.ex)
Generated testc app
Compiling...
% 

but clean doesn’t seem to get called.

% mix clean
% 

I’ve managed to trace this as far as a call to Mix.Task.get/1 in Mix.Tasks.Clean and it appears that the task module Mix.Tasks.Compile.Testc cannot be found.

Can anyone offer any insight? I’ve read the Mix.Task.Compiler behaviour docs but I assume I’ve missed something!?

1 Like