jens
jens

Reputation: 269

versions in elixir dependencies

What is the difference between declaring a dependency to a package using this syntax: "==1.2.3" (which I understand, it is clearly explained in the spec), and just "1.2.3" (which I also see being used, but it is not explained in the script) ? Is this like a soft constraint, that gives the package manager some freedom to resolve to another version?

Thanks

Upvotes: 4

Views: 2121

Answers (3)

Adam Millerchip
Adam Millerchip

Reputation: 23091

According to the Version documentation. What you're talking about is a requirement.

Version:

In a nutshell, a version is represented by three numbers

Requirement:

Requirements allow you to specify which versions of a given dependency you are willing to work against. Requirements support common operators like >=, <=, >, ==, and friends that work as one would expect

Neither the Version documentation nor the mix documentation say anything about specifying the version number (without an operator) directly as a requirement, so that's probably non-standard practice and best avoided.

Requirements are usually specified with the ~> operator because that specifies that a version with a higher least-sigificant digit can be used. For example ~> 1.1.0 would allow 1.1.1, 1.1.2 etc. to be used, but not 1.2.0. There is a useful table in the official documentation.

Upvotes: 1

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

A dependency might by specified as:

  • "== 1.2.3" effectively the same as "1.2.3", meaning “exactly this version”
  • ">= 1.2.3", meaning “any version greater or equal that that, including major versions updates”
  • "<= 1.2.3", meaning “any version that is not greater that that”
  • "~> 1.2.3", meaning “same major version, same minor version with any subversion greater or equal than 3
  • "~> 1.2", meaning “same major version, with any minor version greater or equal than 2

The syntax "~> 1" is disallowed, because it’s effectively the same as ">= 1.0.0".

So, to have some flexibility people usually do "~> 1.2.3" or "~> 1.2" if they trust the package using proper semantic versioning. ">= 1.2.3" is not advised because even with semantic versioning major versions might contain breaking changes.

Upvotes: 7

Ivan Yurov
Ivan Yurov

Reputation: 1618

I believe "1.2.3" is equal to "==1.2.3", which I have never seen been used. But I can't support it with reference unfortunately. But it always behaves like exact match.

UPDATE Yup, look here: https://github.com/elixir-lang/elixir/blob/f47792547b72ee3043da7205a50e4a1fca2a93dd/lib/elixir/test/elixir/version_test.exs#L52

Upvotes: 3

Related Questions