I need to exclude a jar from runtime dependency via Gradle.
I am getting this error:
Caused by: java.lang.IllegalStateException: Conflicting persistence unit definitions for name 'ldb-jpa': file:/D:/EricFrancis/shared/build/libs/shared.jar, file:/D:/EricFrancis/shared/build/resources/main
I'm trying to exclude the jar.
How do I tell gradle to do this?
Without more information (Gradle version, relevant parts of build script, etc.), it's hard to say. But since this isn't a Maven or Ivy dependency, I'd consider not adding it in the first place.
It turns out that I did not understand how configurations worked.
I was able to exclude the jar via:
configurations {
testRuntime {
exclude module: 'share'
}
testCompile {
exclude module: 'share'
}
}
Related
I'm trying to run spring boot project, but i get this error.
any idea what error is this ?
Cannot find JAR 'aws-java-sdk-core-1.11.948.jar' required by module 'gradle-resources-s3' using classpath or distribution directory '/home/mbunderline76/.gradle/wrapper/dists/gradle-7.3.2-bin/4k4cn06q0rruwh9dpndf9gmi8/gradle-7.3.2'
You need to add dependency for the jar required by your gradle version. Trying adding this dependency and refreshing your gradle.
implementation group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.948'
or
implementation 'com.amazonaws:aws-java-sdk-core:1.11.948'
Running on M1 Mac with Kotlin, Adding
configurations.all {
resolutionStrategy {
force ("software.amazon.awssdk.crt:aws-crt:0.16.12")
}
}
to the build.gradle.kts file (don't forget to refresh) worked for me as a work around per this(https://github.com/awslabs/aws-sdk-kotlin/issues/473) github issue
I have added below dependency in build.gradle file. Eclipse plugin is added in build.gradle.
testCompile 'io.dropwizard:dropwizard-testing:1.2.0'
Once I run gradle eclipse command all the compile dependencies are getting added in classpath but testcompile dependencies are not getting added in classpath.
But testCompile 'io.dropwizard:dropwizard-testing:1.2.0' also has transitive dependencies like mockito. Therefore whenever I am trying to use mockito in my Junit, those are not getting compiled.
I am not sure what is the problem none of the transitive dependency of io.dropwizard:dropwizard-testing:1.2.0 is available
Looking at the dropwizard-testing dependencies here I can't see mockito in the compile scoped dependencies. It's in the test scoped dependencies but that's irrelevant, test scoped dependencies are private to that project and don't become transitive dependencies when the jar is included in another project.
I have conflict problem with dependencies.
My project has two dependencies like this:
dependencies {
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
compile files('path/to/ABC.jar')
}
ABC.jar has its own dependency to javax.servlet:servlet-api:
dependencies {
provided group: 'javax.servlet', name: 'servlet-api', version: '2.5'
}
Here is the problem I am dealing with; I need to use ServletContext interface which is provided by both servlet-api libraries and the compiler uses wrong one.
Gradle auto-resolves version conflicts as described here.
But in my case it doesn't help, because it only works when a dependency has two different versions. In this case; although it's a newer version issue, the name has changed from javax.servlet:servlet-api to javax.servlet:javax.servlet-api. So gradle doesn't auto-resolve this conflict, because it doesn't seem to be a version issue.
The thing I tried was using excluding transitive dependency as described here.
compile files('path/to/ABC.jar') {
exclude group: 'javax.servlet'
}
But it didn't work, it seems exclude doesn't work on local 'jar' files.
Now, I don't know what else to do.
How can I exclude a dependency of a dependency which is added as a local file?
(If the first question doesn't have any answer yet) How can I say to the compiler to use the correct ServletContext interface?
compile files('path/to/ABC.jar') is a file dependency, a file dependency does not have any dependency information, so it does not introduce transitive dependencies. If this ABC.jar is a "fat" jar that has the dependency-classes included in the JAR, it is not suited for usage in something like Gradle, Maven or Ant/Ivy that is supposed to handle the dependencies. You would have to use a proper "thin" version of the dependency with the dependencies properly declared, or you need to "repackage" that JAR in your build script to exclude the dependency classes you don't want to pull in. No dependency management can do this for you.
You can execute gradlew dependencyInsight --configuration runtime --dependency javax.servlet:servlet-api or gradlew dependencies --configuration runtime to find out where the dependency really comes from.
Actually your example should not even compile if I see it correctly, because it should most probably be
compile files('path/to/ABC.jar'), {
exclude group: 'javax.servlet'
}
or
compile(files('path/to/ABC.jar')) {
exclude group: 'javax.servlet'
}
But as I said, with a local file dependency there are no transitive dependencies, so an exclude does not make sense at all anyway.
To make the Gradle version conflict magic work, you can simply tell Gradle that those libraries are actually the same library just with different coordinates by using a module replacement like
dependencies {
modules {
module('javax.servlet:servlet-api') {
replacedBy 'javax.servlet:javax.servlet-api'
}
}
}
Then Gradle sees them as the same library and can do its version conflict resolution magic. Whether the library that needs the old version still works with the new version is a different topic that you have to check and / or try yourself. This like always depends on whether the new version is backwards compatible to the old version.
I have no way to test this now, but I believe your syntax is wrong. I have some examples here that look different, in your case it would be:
compile(files('path/to/ABC.jar')) {
exclude group: 'javax.servlet'
}
As I say, I cannot test it now, check if it helps and give a comment.
I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is javax.ws.rs.core.UriBuilder. The version I want to use is brought in by javax.ws.rs:javax.ws.rs-api:2.0.1. However, we also use the Jira rest client library which has a dependency on the older version of jersey (com.sun.jersey:jersey-core) which has included the java.ws packages bundled in it's jar.
Here is an example snippet from the build file:
dependencies {
compile 'com.atlassian.jira:jira-rest-java-client-core:2.0.0-m31'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'org.glassfish.jersey.core:jersey-client:2.17'
}
I can't remove com.sun.jersey:jersey-core as it uses different package name from the new version and would cause class def not found exceptions in the Jira client.
As far as I can tell, my options at this point are:
Revert to using Jersey 1.x and it's implementation of jsr311
Somehow have gradle exclude the javax.ws package from the old jersey client.
I'd like to keep using the newer version of jersey so #2 would be my ideal solution but I'm not sure if it's even possible. Does anyone know how to go about this? If that's not possible, I'm open to other suggestions.
You can exclude an transitive dependency module like this:
compile ('org.glassfish.jersey.core:jersey-client:2.17') {
exclude group: 'javax.ws.rs'
exclude module: 'javax.ws.rs-api'
}
ref: 50.4.7 here
I found out that com.sun.jersey:jersey-core:1.19 doesn't bundle the javax.ws.rs class files and instead lists them as a compile-time dependency. Adding this snippet to my build.gradle fixed the issue.
configurations.all {
resolutionStrategy {
// For a version that doesn't package javax.ws
force 'com.sun.jersey:jersey-core:1.19'
}
}
exclude the group and module as below.
Ex :
implementation('org.apache.httpcomponents:httpclient:4.5.13') {
exclude group: 'commons-codec', module: 'commons-codec'
}
I'm trying to compile an Android project unsuccessfully. The error message is:
Execution failed for task ':mobile:_compileAppDebug'.
java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
Here are my module's gradle dependencies in which I specify a number of libraries including google Auto:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.auto.value:auto-value:1.0-rc1'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.f2prateek.dart:dart:1.1.0'
}
When I looked at the dependencies I thought I just needed google auto value since that is where the missing method resides but adding the provided does not resolve the issue.
The project gradle file includes the retrolambda plugin
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
Can anyone help me identify which dependencies cause the compile error? Interestingly enough, when I copy the gradle files into an empty project everything runs fine.
Dagger 2.0-SNAPSHOT depends on an Auto SNAPSHOT which had an API change: https://github.com/google/dagger/issues/113
This is perfectly normal and acceptable thing for libraries which are under development. If you cannot tolerate an occasional broken build, do not depend on non-release versions in a manner that can change at any time without warning.
I ran in a similar issue. Some libary I'm using bundles Guava within the jar file.
Thus exluding this specific dependency from the apt configuration fixed the problem:
configurations {
apt.exclude module: 'artifactId-Of-Library'
}