gpt4 book ai didi

sbt - 如何强制特定版本的依赖关系?

转载 作者:行者123 更新时间:2023-12-03 07:32:21 25 4
gpt4 key购买 nike

依赖项bar取决于foo 1.2.3,但是该foo版本存在错误,我需要使用版本1.2.2。
我可以使用force()做到这一点。

libraryDependencies += "foo" %% "foo" % "1.2.2" force()
docs不推荐该方法:

Forcing a revision (Not recommended)

Note: Forcing can create logical inconsistencies so it’s no longer recommended.


这是否意味着SBT具有比 force()更好的方式来使用特定版本的依赖项?如果是这样,该怎么办?
还是我从文档中推断出整个问题是我不建议的?

最佳答案

您可以使用dependencyOverrides:

dependencyOverrides += "foo" %% "foo" % "1.2.2"

无论如何,您都不会避免“逻辑上的矛盾”。如果强制使用版本,则必须手动注意与其他库的兼容性,这是没有办法的。

从文档中:

Overriding a version

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" )

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"

关于sbt - 如何强制特定版本的依赖关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36501352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com