On mix.exs
you can declare dependencies like:
def deps do
[{:plug, "~> 1.0"}]
end
Why does it need to have "~>" instead of simply the version on the second part of the tuple.
I have seen that if it gets the dependency from git, you can write the dependency like:
def deps do
[{:plug, git: "git://github.com/elixir-lang/plug.git"}]
end
get (Mix v1. 12.3) Gets all out of date dependencies, i.e. dependencies that are not available or have an invalid lock.
To add a dependency, you have to add the dependency and version to the list in the deps function. Unlike package managers like npm and yarn, you cannot add dependencies from the command line. A dependency entry looks something like this: { :dependency, "~> 1.0. 0" } .
This fancy arrow is supported by Version module. It rounds your dependency with precision set by the digit, which is left neighbour of the most specific one.
From the docs:
# 2.0.0 and later until 2.1.0 ">= 2.0.0 and < 2.1.0"
Since the example above is such a common requirement, it can be expressed as:
"~> 2.0.0"
Check more examples in the Version
module.
Basically it's for your convinience, because it allows you to upgrade your deps automatically whenever you do mix deps.upgrade
, but it lets you control the upgrade - you could download the upgrade, which crashes your current codebase etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With