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

  @impl true
  def clean do

# 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()



Compiling works as expected.

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

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