简体   繁体   English

为什么 MIX 依赖在语义版本之前有一个“~>”?

[英]Why does MIX dependencies have a “~>” before the semantic version of the dependency?

On mix.exs you can declare dependencies like:mix.exs您可以声明依赖项,例如:

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:我已经看到,如果它从 git 获取依赖项,您可以编写如下依赖项:

def deps do
  [{:plug, git: "git://github.com/elixir-lang/plug.git"}]
end

This fancy arrow is supported by Version module. Version模块支持这个花哨的箭头。 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.查看Version模块中的更多示例。

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.基本上它是为了您的方便,因为它允许您在mix deps.upgrade时自动升级您的 deps,但它可以让您控制升级 - 您可以下载升级,这会使您当前的代码库崩溃等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM