1

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
Zoe
  • 27,060
  • 21
  • 118
  • 148
Alex
  • 7,007
  • 18
  • 69
  • 114
  • Well, for once you can't add the dependency directly to the dependency. You have to use Gradle to add the jar as a dependency. See [this](https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file) – Zoe Oct 11 '17 at 15:33
  • @Zoe, how to state that this local jar overwrites the dependency com.company.was.utils.secure.storage:was-utils-secure-storage:17.8.1? – Alex Oct 11 '17 at 15:42
  • If you want to override a dependency, just remove it. If you have two dependencies for the same thing you'll get zip merge errors. Just remove the line. EDIT: Never mind, the extremely poorly formatted table (now formatted and readable) changes the entire meaning of the question. if you want to override specific packages/dependencies that are a part of a dependency, that's a whole different topic – Zoe Oct 11 '17 at 15:43
  • Yes, I want to overwrite the specific dependencies that are part of dependencies – Alex Oct 11 '17 at 15:50

2 Answers2

1

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.

Adi
  • 2,074
  • 22
  • 26
1

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
  }
}
Bui Anh Tuan
  • 910
  • 6
  • 12