Alex
Alex

Reputation: 7491

How to force Gradle to use a specific jar?

I am new to gradle and got a huge project with a lot of dependencies.

However, I built a specific jar that I want to use instead of the jar in dependencies.
In build.gradle I have the dependency to common:

 "com.company.was.common.utils:was-common-utils:${wasUtilsCommonVersion}",

The dependency that I need to change is as follows:

+--- com.company.was.utils.secure.storage:was-utils-secure-storage:17.8.1
|    |    +--- com.company.security.logging:security-logging:16.11.0 (*)
|    |    +--- com.company.was.security.encrypt:was-security-encrypt:17.8.1
|    |    |    +--- commons-io:commons-io:2.5
|    |    |    +--- commons-codec:commons-codec:1.10
|    |    |    +--- com.company.security.logging:security-logging:16.11.0 (*)
|    |    |    +--- com.company.was.common.utils:was-common-utils:17.7.0 -> 17.2.0

How to force gradle to use the jar I built instead of

com.company.was.utils.secure.storage:was-utils-secure-storage:17.8.1?

The path to the jar is

/Users/anarinsky/eclipse-workspace/was-utils-storage-java/build/libs/was-utils-storage-java-SNAPSHOT.jar

Upvotes: 1

Views: 3105

Answers (2)

Bui Anh Tuan
Bui Anh Tuan

Reputation: 920

You can use DependencyHandler to define which will ne used, which will be ignored. Example:

dependencies {
  compile('org.hibernate:hibernate:3.1') {
    //in case of versions conflict '3.1' version of hibernate wins:
    force = true

    //excluding a particular transitive dependency:
    exclude module: 'cglib' //by artifact name
    exclude group: 'org.jmock' //by group
    exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group

    //disabling all transitive dependencies of this dependency
    transitive = false
  }
}

Upvotes: 1

Adi
Adi

Reputation: 2094

In Gradle the order of adding dependencies will dictates the final jar that will be added, meaning if you add two versions of x.jar Gradle doesn't take the new one or even runs any logic behind it, it will just add them one by one and since they have the same name the last one will overwrite the previous one. In your case just add the one you created last.

Upvotes: 1

Related Questions