简体   繁体   English

Java共享(交叉)依赖性管理

[英]Java Shared (crossed) Dependency Management

Lets say I am building a java application that relies on a two libraries: A and B. Both A and B are dependent on on a library C. What is the best way to manage that A and B are using the same version so they don't conflict? 可以说我正在构建一个依赖于两个库的Java应用程序:A和B。A和B都依赖于库C。什么是最好的管理A和B使用相同版本的方法?不冲突吗? I am using Gradle. 我正在使用Gradle。

Starting from Gradle 4.6 (5.x) Gradle provides support for importing bill of materials (BOM) files , which are effectively .pom files that use <dependencyManagement> to control the dependency versions of direct and transitive dependencies. 从Gradle 4.6(5.x)开始,Gradle 支持导入物料清单(BOM)文件 ,该文件是有效的.pom文件,使用<dependencyManagement>来控制直接和传递依赖项的依赖项版本。 Sounds like what you need. 听起来像您所需要的。 So, if library C has a BOM just import that BOM of the version you want to enforce: 因此,如果库C具有BOM表,则只需导入要执行的版本的BOM表即可:

dependencies {
    // import a BOM
    implementation(enforcedPlatform("com.acme:c-bom:1.0.0"))

    implementation("com.acme:a:1.2.3")
    implementation("com.acme:b:4.5.6")
}

If the library does not have a BOM, just declare it explicitly: 如果该库没有BOM,则只需明确声明即可:

dependencies {
    implementation("com.acme:c:1.0.0")

    implementation("com.acme:a:1.2.3")
    implementation("com.acme:b:4.5.6")
}

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

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