Currently `mix.exs` is always evaluated when compiling project, even when it is only dependency. This has its positive side, but also one negative side: application version need to be hardcoded somewhere, either within `mix.exs` itself or in some file, commonly `VERSION`. However this has main disadvantage - keeping all of them in sync, especially when using SCM as version source. What I am proposing here is to add new function to Mix (I haven't found proper place for it yet) that will read version from some known metadata file (for example `hex_metadata.config` file) and if this file do not exist, then it will fall back to provided callback function, ex.
def project do
[
# …
version: try_cached_version(&version/0),
#…
]
end
def version do
case System.cmd("git", ~w[describe]) do
{version, 0} -> version
_ -> "0.0.0-dev"
end
end
This would allow users to generate version via their project version using SCM of their choice and would not fail when building project as dependency.