Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

java - Multiple version of dependencies in Gradle

i'm building a java project, using gradle for version control.

I'm migrating from an old version of the Drools rules engine 5.5.0 to 6.2.0. Instead of going 'big bang' and change everey class to use the new version, I would like to change one class at the time, and remove the old dependency when all the classes are migrated.

In my gradle.build I have set:

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'

But it only downloads the newest version of the libraries. Does gradle support multiple versions of the same library?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To download multiple version of the same library:

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

refer to: How to get multiple versions of the same library

By the way

  • above download two versions, while compiling with only one version

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.

refer to: 23.2.3. Resolve version conflicts of Chapter 23


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...