java - Gradle 中的多个依赖项版本

标签 java gradle

我正在构建一个 java 项目,使用 gradle 进行版本控制。

我正在从旧版本的 Drools 规则引擎 5.5.0 迁移到 6.2.0。 我不想“大爆炸”并更改每个类以使用新版本,而是想一次更改一个类,并在迁移所有类时删除旧的依赖项。

在我的 gradle.build 中我设置了:

compile 'org.drools:drools-compiler:6.2.0.Final'
compile 'org.kie:kie-api:6.2.0.Final'  
compile 'org.drools:drools-core:6.2.0.Final'

compile 'org.drools:drools-core:5.5.0.Final'
compile 'org.drools:drools-compiler:5.5.0.Final'

但它只下载最新版本的库。 gradle 是否支持同一个库的多个版本?

最佳答案

下载同一个库的多个版本:

repositories {
  mavenCentral()
}
  configurations {
  compile5
  compile6
}
  dependencies {
  compile5 'org.osgi:org.osgi.core:5.0.0'
  compile6 'org.osgi:org.osgi.core:6.0.0'
}
  task libs(type: Sync) {
  from configurations.compile5
  from configurations.compile6
  into "$buildDir/libs"
}

引用:How to get multiple versions of the same library

顺便说一下

  • 上面下载了两个版本,同时只编译了一个版本

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.

引用:23.2.3. Resolve version conflicts of Chapter 23

关于java - Gradle 中的多个依赖项版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29374885/

相关文章:

Java 线程在不关注 OSX 时进入 hibernate 状态

java - 如何从枚举中提取所有值并将它们添加到 List<String>

gradle - 如何强制Gradle在 `main`中进行测试?

gradle - 与Gradle依赖相混淆

Java、gulp和maven文件夹结构

gradle - Gradle任务依赖

java - 网络驱动程序 : want to get the child elements of an element created using@FindBy

java - 如何检索 SSL 客户端正在使用的 KeyManager、TrustManager 和 SecureRandom 对象?

oop - Java 核心库中的 GoF 设计模式示例

java - 是否可以阻止 Gradle 添加排除的传递依赖项?