Mix release generates multiple versions of the same application when building release

When building a release with elixir 1.9.x mix generates a _build/prod/rel/my_app folder, with a directory structure like the following:


Say my app is in version 0.1.0, when I build the release with mix release, it will compile the whole project the first time and create a directory my_app-0.1.0 in _build/prod/rel/my_app/lib containing the compiled .beam files and other assets.
Now say I bump my app version to 0.1.1 and run mix release again. This time it wont compile the files that were already compiled so this step will take less time than the first time. But it will create a my_app-0.1.1 directory with duplicated content from my_app-0.1.0.

This is also true for dependencies, so the issue can get out of hands pretty quickly.

Is there a way to prevent this, or to clean the old versions from the release? (something like mix phx.digest.clean)

I’ve noticed that in _build/prod/rel/my_app/releases/vsn there’s a my_app.rel written in erlang. It’s contents have the form:

%% coding: utf-8
{release, {"my_app", "current version"}, {erts, "erts version"},
  {app1, version, _some_flag},
  {app2, version, _some_flag},

The apps and versions there seem to be the latest ones. Maybe it could be used as a manifest to implement a mix release.clean task?

Reading this commit it seems this issue was already solved and merged to master, but it didn’t make it to the 1.9.2 release