SBT 如何在依赖项中选择最高版本? [英] How could SBT choose highest version amongst dependencies?
问题描述
这是一个关于版本控制和工作流程的问题.
This is a question about versioning and workflow.
我有多个项目
projectA/build.sbt
version := "1.0.0"
libraryDependencies ++= Seq(
"com.example" % "projectB" % "1.0.0",
"com.example" % "util" % "1.0.0"
)
projectB/build.sbt
version := "1.0.0"
libraryDependencies ++= Seq(
"com.example" % "util" % "1.0.0"
)
util/build.sbt
version := "1.0.0"
------------------------ 发展 ------------------------
------------------------ DEVELOPMENT ------------------------
我在 util
中添加了一个方法.
I added a method in util
.
util/build.sbt
version := "2.0.0"
这个添加的功能很棒,所以我用它来优化projectB
.
This added functionality is great, so I use it to optimize projectB
.
projectB/build.sbt
version := "1.1.0"
libraryDependencies ++= Seq(
"com.example" % "util" % "2.0.0"
)
------------------------ 发展 ------------------------
------------------------ DEVELOPMENT ------------------------
我希望 projectA
更快,所以我引入了 projectB
.
I want projectA
to be faster, so I pull in projectB
.
projectA/build.sbt
version := "1.1.0"
libraryDependencies ++= Seq(
"com.example" % "projectB" % "1.1.0",
"com.example" % "util" % "1.0.0"
)
------------------------ 问题 ------------------------
------------------------ PROBLEM ------------------------
现在,projectA
需要 util
版本 1.0.0
,但是 project B
需要 util
版本 2.0.0
.
Now, projectA
requires util
version 1.0.0
, but project B
requires util
version 2.0.0
.
我可以更新 projectA
以使用新版本的 util
.问题是我需要更新的项目和依赖项的数量可能非常大,而且依赖项链可能很长.(想象一下 projectZ
依赖于 projectA
和 util
.)
I can update projectA
to use the new version of util
. The issue is that the number of projects and dependencies I need to update can be be very large, and the chain of dependencies can be very long. (Imagine projectZ
which depends on projectA
and util
.)
有没有办法让我的项目依赖项具有最低版本?
例如,如果 projectA
需要 util
版本 1.0.0
而 projectB
需要 util
版本 2.0.0
,projectA
将使用 2.0.0
版本.
For example, if projectA
needs util
version 1.0.0
and projectB
needs util
version 2.0.0
, projectA
will wind up using the 2.0.0
version.
如果是这样,如果有 util
的 3.0.0
版本可用,在这种情况下会发生什么?projectA
最终会使用 2.0.0
还是 3.0.0
?
If so, what would happen in this case if there were version 3.0.0
of util
available? Would projectA
wind up using 2.0.0
, or 3.0.0
?
对我来说,如果我可以让一个项目使用最大的版本,从它自己的依赖项和(递归地)它的依赖项的依赖项中,但不高于那个,那将是理想的.
For me, it would be ideal if I could have a project use the greatest version, from among its own dependencies and (recursively) its dependents' dependencies, but no higher than that.
推荐答案
对我来说,如果我能有一个项目使用最大的版本,从它自己的依赖项和(递归地)它的依赖项的依赖项,但不高于此.
For me, it would be ideal if I could have a project use the greatest version, from among its own dependencies and (recursively) its dependents' dependencies, but no higher than that.
来自 Sbt 文档 http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management.html#conflict-management :
From the Sbt documentation http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management.html#conflict-management :
冲突管理器决定依赖解决时要做什么引入了同一库的不同版本.默认情况下,选择了最新版本.
The conflict manager decides what to do when dependency resolution brings in different versions of the same library. By default, the latest revision is selected.
这已经是默认行为了.
相同的文档解释了如何强制版本、指定最低版本等
The same documentation explains how to force version, specify minimum version, etc.
这篇关于SBT 如何在依赖项中选择最高版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!