Cleaning unused deps as early as possible

Hello guys, I’m having a small problem and dilemma in my project. I want to clean the unused dependencies as early as possible, i.e. anywhere from right after using mix deps.get and calling the first function or whatever the first step may be.

I was trying to use "deps.clean", ["--unused"] right at the end of the mix.exs file, but for some reason this doesn’t seem to be possible?

The only other way I see about doing this is to have a module or application that is run when the project is started up, but this seems like overkill to run just a single line of code.


Have you looked at Aliases? They are basically tasks you can setup for your specific project in your mix.exs file. Take a look at the docs to see how they are implemented:

defmodule Hihi.Mixfile do
  use Mix.Project

  def project do
    [app: :hihi,
     version: "0.0.1",
     elixir: "~> 1.2",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     aliases: aliases,
     deps: deps]

  def application do
    [applications: [:logger]]

  def aliases do
    # what you want this project specific task to do

  defp deps do

Actually, I just found a better solution.

When a release is generated with Exrm, only the necessary deps are included in the release. So my problem only affects my project when in dev, but it won’t be an issue on prod :slight_smile:


mix deps.clean --unused is meant as auxiliary task during development, usually you do it once everywhile, or whenever you have removed a dependency from mix-file or you have run mix deps.update.

When you don’t change the dependencies then there is not even the need to clean.

This is not meant to get a clean build by removing old artifacts, but only to free disk space.