Maven shade plugin is very powerful for resolving dependency conclict, but a situation I have is as follows :
myproject
guava 31
thridparty-dependency-1
guava18
I could relocate the guava 31 dependency and then the conflict will be resolved. And how about following situation :
myproject
thirdparty-1
guava31
thirdparty-2
guava18
thirdparty-3
guava4
Or how about if there are more than two dependencies conflicting as the same dependency but with different versions ?
If I use relocation, then thirdparty-1/guava31 will be relocated but the guava18 and guava4 still conflict.
I'm not sure how to handle this situation.
You need to de-conflict these across the whole project, not just for the shaded uber-jar.
Use Maven <exclusions> in the pom.xml declarationtion to achieve this.
For example:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>${neo4j.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>${netty.version}</version>
</dependency>
Related
I need to integrate this dependency within my maven project:
<!-- https://mvnrepository.com/artifact/org.apache.beam/beam-sdks-java-io-google-cloud-platform -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>2.11.0</version>
</dependency>
However, when I try to execute the command mvn verify within my project I get the error attached:
thanks for the help!
Update
I have included my pubsub dependency like:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.69.0</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
</exclusions>
</dependency>
The functions offered by Beam are not suitable for my project unfortunately.
What you are describing is the Diamond Dependency problem.
If you can use the same version of pubsub as beam you should not have this conflict. Per Maven Central, beam-sdks-java-io-google-cloud-platform depends on grpc-google-cloud-pubsub-v1 1.43.0.
I have figure it out the point is that I had on my pom.xml the dependency :
<!-- <dependency>-->
<!-- <groupId>com.google.cloud</groupId>-->
<!-- <artifactId>google-cloud-pubsub</artifactId>-->
<!-- <version>1.66.0</version>-->
<!-- </dependency>-->
But then how should I do if I need to work with these two dependencies on the same project?
Despite having appropriate jars in classpath Spring Boot throws - java.lang.ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer
Any suggestions what is missing here.
I have added the respective starters in pom.xml as shown below:
<dependency>
<groupId>org.springframework.boot</groupId>[![enter image description here][1]][1]
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
</dependency>
The project maven dependencies also shows the class availability, as in given image attachment.
the answer is here - https://stackoverflow.com/a/34271507/2885422 It all depends how maven loads the class. There are 2 version of camel-spring.jars available in classpath (2.20.1 and 2.19.3. Ref: my original post image)
And org.apache.camel.spring.spi.XmlCamelContextConfigurer class is available only in 2.20.1 jars. And maven by default looks in earlier one and once package found matching but no class found throws error (?)
And the reason I believe 2.19.3 get loaded is Apache-cxf jars is of 2.19.3. Unfortunately our project repository does not have apache-cxf starter jars.
https://stackoverflow.com/a/34271507/2885422
Solution: - I hope it may be helpful for future references
By adding options I could resolve the issue,by having exclusion clause added as given below. Thus I could load only required version jars.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</exclusion>
</exclusions>
</dependency>'
I excluded an artifact because it causes conflicts, namely the jsr311-api given below. Yet when I run the generated jar I'm still getting the java.lang.NoSuchMethodError error. I suspect that another dependency is also including this artifact. How can I find out which one? My dependency list is quite large. Which dependencies include the package javax.ws.rs.core?
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.7.3</version>
<exclusions>
<!-- Causes java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family; -->
<exclusion>
<artifactId>jsr311-api</artifactId>
<groupId>javax.ws.rs</groupId>
</exclusion>
</exclusions>
</dependency>
Go to
http://search.maven.org/#advancedsearch%7Cgav
and use classname search to find
javax.ws.rs.core.Response
If you use a Nexus 2.x in your company, you can use classname search there as well.
If you want to find out where a given artifact (that you e.g. found by classnmae search) comes from, use dependency:tree in Maven.
In my case the mistake was that I had to manually add the javaee api and I set <scope>provided</scope> which was a mistake, fixing this solved the problem.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope><!-- remove this -->
</dependency>
If I have some libs that have others dependencies in different versions like this example: commons-logging-1.0.4.jar (omitted for conflict with 1.1.1) and commons-logging-1.1.1.jar.
What´s the best practice about this, inform the exclusion of this conflict in the related dependency (by tag) or do nothing because the lib was omitted? Is there any problem don´t especify the exclusion of dependencies in the POM ?
Example that explain that how to resolve this in the POM, I´m putting the following instruction to resolve the internal conflicts about version:
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.2.8</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
You need to configure a dependencyManagement section in your [parent] POM. This will coerce artifacts coming as transitive dependencies to be of the specified version.
How can I remove artifacts from the lib folder of the ear? For exemple: activation.jar.
I was try follow the especification about Excluding a module (just change webModule for jarModule) but without success with this error: Artifact[jar:javax.activation:activation] is not a dependency of the project.
Use provided as scope wherever the dependency is defined.
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
Set the scope to provided. Maven will still add the dependency to the compile time classpath but not to the final WAR.
As others have said, you need to use provided as the scope. If the jars you need to remove are not dependencies of your project directly (ie are transient dependencies), then you need to exclude them from whatever is bringing them into your build . If you actually need those classes at compile-time, you'll have to re-include them as provided:
<dependency>
<!-- this dependency has javax.activation as a dependency -->
<groupId>blah.groupId</groupId>
<artifactId>blah.artifactId</artifactId>
<version>blah.version</version>
<exclusions>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<exclusion>
</exclusions>
</dependency>
<!-- only necessary if this jar is needed at compile-time -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>