Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple version of dependencies in Gradle

Tags:

java

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?

like image 503
bjar-bjar Avatar asked Mar 31 '15 17:03

bjar-bjar


People also ask

How do I force Gradle to use specific dependency?

If the project requires a specific version of a dependency on a configuration-level then it can be achieved by calling the method ResolutionStrategy. force(java. lang. Object[]).

Can I use different Gradle versions for different modules?

Gradle does not support multiple Gradle versions in the same multi project build. This is also not supported in composite builds. Given the constraints, the easiest solution would be to work with a local repository to which you publish and from which you fetch your cross project dependencies.

How do you update dependencies in build Gradle?

Perform a Gradle sync/reloadThe file versions. properties is part of the Gradle build. Consequently, after you have edited it, you need to ensure the IDE gets the changes. Android Studio: Run the “Sync Project with Gradle Files” action (via ctrl / cmd + shift + A ), or click the elephant + arrow icon in the toolbar.

How do I specify the latest version of Gradle?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line. The preferred way is to use the Gradle Wrapper command line tool, which updates the gradlew scripts.


2 Answers

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

like image 169
keke2048 Avatar answered Oct 16 '22 09:10

keke2048


No gradle doesn't support multiple version of the same library. It will choose the newest by default but you can change this using

org.gradle.api.artifacts.ResolutionStrategy.failOnVersionConflict()

In case of conflict, Gradle by default uses the newest of conflicting versions. However, you can change this behavior. Use this method to configure the resolution to fail eagerly on any version conflict, e.g. multiple different versions of the same dependency (group and name are equal) in the same Configuration.

Taken from here https://gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

like image 36
mushfek0001 Avatar answered Oct 16 '22 10:10

mushfek0001