问题描述
一个依赖 bar
依赖于 foo
1.2.3,但是那个版本的 foo
有一个错误,我需要使用 1.2 版本.2.
A dependency bar
depends on foo
1.2.3, but that version of foo
has a bug and I need to use version 1.2.2.
我可以用 force()
做到这一点.
I can do that with force()
.
libraryDependencies += "foo" %% "foo" % "1.2.2" force()
docs 不推荐这种方法:
强制修改(不推荐)
注意:强制会造成逻辑上的不一致,因此不再推荐.
Note: Forcing can create logical inconsistencies so it’s no longer recommended.
这是否意味着 SBT 有一种不同于 force()
的方式来使用特定版本的依赖项?如果有,是什么?
Does this mean SBT has a different, better way than force()
to use a specific version of a dependency? If so, what?
或者我是否应该从文档中推断出这整个问题是我建议不要遇到的问题?
Or am I to infer from the documentation that this entire problem is one that I'm recommended not to have?
推荐答案
你可以使用 dependencyOverrides:
dependencyOverrides += "foo" %% "foo" % "1.2.2"
无论如何,您并没有避免逻辑不一致".如果你强制一个版本,你必须手动处理与其他库的兼容性,这是没有办法的.
You're not avoiding "logical inconsistencies" anyway. If you force a version, you have to manually take care of compatibility with other libraries, there's no way out of that.
来自文档:
覆盖一个版本
对于二进制兼容的冲突,sbt 提供依赖覆盖.它们使用dependencyOverrides 设置进行配置,这是一个一组 ModuleID.例如下面的依赖定义冲突,因为 spark 使用 log4j 1.2.16 而 scalaxb 使用 log4j1.2.17:
For binary compatible conflicts, sbt provides dependency overrides. They are configured with the dependencyOverrides setting, which is a set of ModuleIDs. For example, the following dependency definitions conflict because spark uses log4j 1.2.16 and scalaxb uses log4j 1.2.17:
libraryDependencies ++= Seq(
"org.spark-project" %% "spark-core" % "0.5.1",
"org.scalaxb" %% "scalaxb" % "1.0.0" )
默认的冲突管理器选择log4j的最新版本,1.2.17:
The default conflict manager chooses the latest revision of log4j, 1.2.17:
show update
[info] compile:
[info] log4j:log4j:1.2.17: ... ...
[info] (EVICTED) log4j:log4j:1.2.16 ...
更改版本选中,添加一个覆盖:
To change the version selected, add an override:
dependencyOverrides += "log4j" % "log4j" % "1.2.16"
这篇关于如何强制特定版本的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!