gpt4 book ai didi

gradle - Gradle如何处理冗余依赖关系

转载 作者:行者123 更新时间:2023-12-03 04:23:26 25 4
gpt4 key购买 nike

如果我的build.gradle文件中有两个依赖项引用了组 Artifact ,而这两个组都包含了对同一jar文件的引用,那么Gradle会如何处理它们? Gradle是否能够识别组成该组的各个jar文件之间的版本差异,并且仅在进行编译时选择具有最新版本的版本,还是会选择build.gradle文件中最后列出的版本?例:

dependencies {
compile group: 'some-sdk-1', name: 'sdk1', version: '2.5'
compile group: 'some-sdk-2', name: 'sdk2', version: '1.0'
}

在此示例中,some-sdk-1可能包含一个名为lib1-1.0.jar的jar。
在some-sdk-2中,存在相同的库,但版本不同。例如lib1-2.0.jar

使用哪个jar文件?

最佳答案

这取决于jar文件如何放入库(sdk)中。
您应该将jar文件作为可传递依赖项进行管理。
这意味着在与sdk相关的pom文件中,您具有jar文件的依赖项。
在这种情况下,您可以check the doc:

Gradle offers the following conflict resolution strategies:

Newest: The newest version of the dependency is used. This is Gradle’s default strategy, and is often an appropriate choice as long as versions are backwards-compatible.

Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. See ResolutionStrategy for details on how to explicitly choose a particular version.


相反,如果您只是将jar放在sdk 中,而不使用传递依赖项(只是jar文件放在其中):

If you don’t use transitive dependency management, version conflicts are undetected and the often accidental order of the classpath will determine what version of a dependency will win.

关于gradle - Gradle如何处理冗余依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48638689/

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