marcandre
Specifying minimal Erlang version in mix.exs
Is it still not possible to specify Erlang compatibility in mix.exs?
Erlang/OTP is a dependency of Elixir, so it is an indirect dependency of any mix projects, but it may be a direct dependency too. mix.exs should be able to convey that and mix should be able to resolve dependencies handling this too.
As a practical example, :crypto.hmac/3 no longer exists in OTP 24, one must use :crypto.mac/4 which is OTP 22+
If a package maintainer wants to use :crypto.mac/4, the only easy choice is to require the shiny new Elixir 1.12, because Elixir 1.11 is compatible with OTP 21
Ideally one could say: compatible with Elixir >= 1.7 but OTP >= 22.
Most Liked
josevalim
Correct, it is still not supported because we want to avoid adding multiple dimensions for system dependencies. So in this sense it would be preferable to either supporting v1.7 and all OTP versions by checking which crypto function is available (that’s what we did in plug_crypto) or bumping to v1.12.
However, if occurrences like this keep happening, then we should probably be more pragmatic and allow the OTP dependency.
eksperimental
Interesting request. Totally doable.
It will not compile if it does not meet the :otp dependency requirement.
$ mix
** (Mix) You're trying to run :otp_dependency on Erlang/OTP 24.0.0 but it has declared in its mix.exs file it supports only Erlang/OTP ~> 24.1
josevalim
It doesn’t work on dependency resolution. It just emits a warning (or raise) if you don’t have a matching version. If this behaviour is enough for you, then you can check for the OTP release in your mix.exs.
wojtekmach
There is a couple of problems:
- We have
System.otp_release() # => "26"but notSystem.otp_version() #=> "26.1.2"and the reason is the latter is not exposed by OTP. There are hacks to get this version out, you can see whatmix hex.infodoes for example, but the first step would be to have OTP expose this. - Adding
:minimum_otp_release/:otp_versionto mix.exs that works like :elixir, i.e. does not participate in resolution, should be fairly straightforward. Adding it in a way that participates in resolution is a rather big undertaking.
mix.exs is executable so something everyone can do today is:
if System.otp_release < "26" do
IO.puts "this package requires OTP 26. Install foo v0.2.0 that works with prior OTP versions"
raise "incorrect OTP"
end
defmodule Foo.MixProject do
and the benefit is the error message can be as succinct or as verbose as you want it to be. In that sense it’s better than when provided by the build tool because you have full control what extra information to include.
hauleth
You can always have runtime/compile time check that will pick the best available option.







