Is there a way to include two versions of the same artifact in Maven? - maven

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>1.2.0</version>
</dependency>
<!--Include Both Jmock 1&2 is cool: http://www.jmock.org/upgrade1to2.html -->
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.5.1</version>
</dependency>
This doesnt work.

Check out the dependency mediation section in http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html . One version will win.

Related

SpringBoot Keycloak NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates

I probably have an issue with my POM in my SpringBoot App.
Currently I am trying to access my Keycloak Server with the
"admin-client-keycloak"
But on the call:
Response response = getInstance().realm(REALM).users().create(user);
I get Error:
java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates(Ljava/util/Map;)Ljavax/ws/rs/core/UriBuilder;
at org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.resolveTemplates(ClientWebTarget.java:178) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
at org.jboss.resteasy.client.jaxrs.internal.proxy.SubResourceInvoker.invoke(SubResourceInvoker.java:65) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
at com.sun.proxy.$Proxy198.realm(Unknown Source) ~[na:na]
at org.keycloak.admin.client.Keycloak.realm(Keycloak.java:118) ~[keycloak-admin-client-3.4.3.Final.jar:3.4.3.Final]
To be honest: I am not a Maven expert and stitched it together from several web soultions and I expect that some parts are still outdated or something.
the POM dependecys:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
<scope>runtime</scope>
</dependency>
<!-- Keycloak -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>3.4.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.5.1.Final</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>3.4.3.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
The Error occurs from the 'keycloak-admin-client' module.
Now the main question is:
Whats the problem? Or is it realy a bug inside the version of 'keycloak-admin-client'?
I guess not which leads my to a second question:
How can I found out what I need to change in a situation like this?
Thanks in advance for all suggestions. I primary want to learn how to solve such issues by my own in future.
Kind regards
Gregor
EDIT:
Well I am a step further but the issue is still there.
The POM I show you here is a POM of library which is used in other projects.
These Project have a 'spring-Boot-starter' which are using the 'jersey' version:1.54.
So the problem seems clear.
I added the 'jersey 2.0.2' dependency in the final project POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
But the issue still exists.
How can I force maven use the 2.0.2 version and override the 1.5.?
Only adding the dependecy doesnt seems to help.
Some of the other dependencies are using a different version of the lib jsr311-api. In my case it was the eureka client. I just added an exclude with this dependency in the pom and it worked
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Please make sure UriBuilder class exist on your project. And make sure only one UriBuilder class (version) exist in your project. (It can be multiple on your project with different versions.) Different versions can be overlapped.
keycloak-admin-client version should same with your keycloak server version.
add additional dependency to pom (versions must be added, for keycloak 3.0.0.Final => resteasy dependecies 3.5.0.Final works for me. Dependencies must be complied.)
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
</dependency>
Note: This is my suggestion, if you are develop multi-layer app. You can divide your project to layers. You can divide your spring boot starter app and keycloak access layer. And use this new project as dependecy.
edit,
see Failed adding user by keycloak-admin-client to Keycloak due to "unknown resource"
i hope these can helps.

How to exclude jasperreports artifact from jasperreports maven plugin

I have below plugin in my pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<dependencies>
<dependency>
<!-- The dependency specified by the plugin doesn't work so we must provide our own -->
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
<exclusions>
<exclusion>
<groupId>jfree</groupId>
<artifactId>jcommon</artifactId>
</exclusion>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Groovy compiler seems to be required but not part of JasperReports' specified dependencies-->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>${itext.version}</version>
</dependency>
</dependencies>
</plugin>
The 1.0-beta-2 version of the above plugin points to jasperreports artifact of version 1.2.0, which in turn points to an open-ended commons-collections of [2.1, )
In 1.0-beta-2 pom:
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>1.2.0</version>
</dependency>
And in jasperreports 1.2.0 pom:
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>[2.1,)</version>
<scope>compile</scope>
</dependency>
In my case, there has been an push by someone else to a nexus repostiory, an artifact called 3.2.1-redhat-7 commons-collections.
jasperreports-maven-plugin is pointing to the above collections version which happens to be a corrupt one. There is a valid 3.2.1 version of commons collection. I need to exclude the jasperreports artifact and force the jasperreports-maven-plugin to use net.sf.jasperreports.
I have alread tried adding
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</exclusion>
</exclusions>
</dependency>
to the above plugin, but it still points to the same 1.2.0 jasperreports that points to an open-ended commons-collections, and the build fails.
However if i comment out the dependency "jasperreports" in the jasperreports-maven-plugin.pom, it uses the jasperreports from net.sf.jasperreports and builds fine.
Please let me know.
Sorry for not really answering (can't comment yet due to lack of reputation), but:
1.
in case you are in a hurry the way i was,
here is a workaround, from
http://community.jaspersoft.com/questions/967926/issue-maven-plugin-codehaus-dec-9-2015:
You need to add
https://maven.repository.redhat.com/nexus/content/groups/product-ga
as one of your remote repos.
thanks a lot to joel.witham
2.
I think that this answer to
Maven dependency management for plugin dependencies
is most promising..i.e. don't exclude jasper-1.2 but make sure it's using the correct dependency version.
Try this configuration :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
...
<dependencies>
...
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>1.2.0</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>

The exclusion tag can't solve the duplicated dependency version

Here is my problem, I have a parent pom.xml which defines the:
--------parent pom.xml-----------------
<dependencyManagement>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0.3</version>
</dependency>
</dependencyManagement>
Inside this roboletric pom.xml we have:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-ant-tasks</artifactId>
<version>2.1.3</version>
</dependency>
Inside the maven-ant-tasks pom.xml, it has:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.2.1</version>
</dependency>
So whenever I am calling the API which only exists in the maven-artifact 3.0.3 in the roboletric test case, it will throw nosuchmethod exception.
So I have tried:
1. <dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
<version>2.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
I also tried moving:
org.apache.maven
maven-artifact
3.0.3
to the child pom under the <dependencyManagement> which I think it should override the parent but actually it didn't.
I think this kind of problem should be very common but I just can't figure it out, any suggestions?
You should define dependency management in your parent POM to nail down the version of maven-artifact in all (transitive) dependencies:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
</dependencyManagement>

Artifact Name not matching the maven repo URL path

Isn’t the artifact name under below URL wrong?
http://repo1.maven.org/maven2/org/powermock/powermock-mockito-release-full/1.5.1/
As per above URL, The name of the artifact should have been powermock-mockito-release-full-1.5.1.jar but what I see is powermock-mockito-release-full-1.5.1*-full*.jar. The additional –full is breaking my maven build (unable to find resource). Below is my dependency declaration and how different I should declare the POM dependency than below one.
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-mockito-release-full</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
Am I missing something?
Thanks
The last full in this repository is another dependency coordinate called classifier.
Try adding the classifier and you should download the dependency:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-mockito-release-full</artifactId>
<version>1.5.1</version>
<classifier>full</classifier>
<scope>test</scope>
</dependency>
I suggest to avoid classifier because their values are not standard and therefore their meaning and the way to use them is not always so clear.
Looking at the mockito site you should include the dependency like so:
http://code.google.com/p/powermock/wiki/Mockito_maven
<properties>
<powermock.version>1.5.4</powermock.version>
</properties>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Errors when executing maven install with glassfish-embedded-all and arquillian-glassfish-embedded-3.1 artifacts

I'm trying to execute maven install on a pom and the result shown is:
Grave: SEC5054: Certificate has expired
This result appears just after test execution begins.
I have been googling over this problem but I've only found solutions that are related to a real glassfish application server. They recommend things like deleting the offending certificates from the folder where they are located and so on (the pages I've seen are mostly like this) or 'unjar' the glassfish-embedded to remove the certification and then jar it again.
Notice that I'm executing a maven install, not an actual deployment on an application server. That's why I cannot take the advice given at many blogs
The pom includes the following dependencies:
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
This is a known issue at least since Glassfish 3.0.1 and still reported as an Open Issue in Glassfish 3.1.2. Oracle provides some workarounds - that all doesn't apply to your situation. But they also say:
If the instance is not configured this way, ignore the warning. The functionality of the instance is unaffected.
So even if this is a lame answer to a SO question: Don't bother for your test-cases. (Personally I spend far to much time trying to solve the issue.) Either a new version of Glassfish will resolve this issue for us or it will not. Let's stop bothering.
Update:
If you have problems that this triggers a failed build, the following pom works for me without a failed build:
<!--snip-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.3.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.7.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
You can try this:
Create a custom domain.xml
Change <jvm-options>-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks</jvm-options> to <jvm-options>-Djavax.net.ssl.trustStore=insertpathtocacert/cacerts.jks</jvm-options>
Configure arquillian.xml setting configurationXml to be the path to domain.xml: https://docs.jboss.org/author/display/ARQ/GlassFish+3.1+-+Embedded
or this: Arquillian Embedded Glassfish Certificate Expired
I assume that the test phase starts the embedded glassfish server which is responsible for the error. Install phase is after Test phase. If you want to execute any test cases, you have to unjar and remove the conflicting certificates (in .m2 folder). Else you can bypass the test phase by using a flag -DskipTests=true.

Resources