MAVEN : Is There A Possibility to Personnalize the Tree of dependencies in Maven Project - spring-boot

In my Pom.XML, there is two dependency that get with them the: 'org.keyclaok:keycloak-core' dependency:
<dependency>
<groupId>ma.s2m.nxp</groupId>
<artifactId>nxp-keycloak-starter</artifactId>
<version>1.1.0</version>
</dependency>
which is a starter developped by the company that come with the 'org.keycloak:keyclaok-core' version 13.0.0,
<dependency>
<groupId>io.strimzi</groupId>
<artifactId>kafka-oauth-client</artifactId>
<version>${strimzi-oauth-callback.version}</version>
</dependency>
This dependency come with 'org.keycloak:keycloak-core' version 11.0.2,
and the strimzi-oauth-callback.version property is 0.6.1
When i run mvn dependency:tree, i get the 'org.keycloak:keycloak-core' with the version 11.0.2 (the dependency that come with 'kafka-oauth-client'), and i need it to come from 'nxp-keycloak-starter'

Related

Update Maven dependency version in multiple ServiceMix POMs

I am trying to automate process of changing version of a product that has ServiceMix (FuseESB) as an integration module.
Changing the version in each POM is quite easy with the Maven versions plugin:
mvn versions:set -DnewVersion=NEW_VERSION -DgenerateBackupPoms=false
However, I am now struggling with updating version in dependencies that are other modules of this product. Particularly, in many Service Units' POM files there are dependencies like these (where OLD_VERSION is the same, older version number):
<dependencies>
<dependency>
<groupId>com.company.department.product.module1</groupId>
<artifactId>artifact1</artifactId>
<version>OLD_VERSION</version>
</dependency>
<dependency>
<groupId>com.company.department.product.module1</groupId>
<artifactId>artifact2</artifactId>
<version>OLD_VERSION</version>
</dependency>
<dependency>
<groupId>com.company.department.product.module2</groupId>
<artifactId>artifact3</artifactId>
<version>OLD_VERSION</version>
</dependency>
</dependencies>
And I would like to set the version number in those dependencies to "NEW_VERSION".
Do you guys have any ideas?
Just found very simple solution for this - replace dependencies' version with ${project.version} - works for me because in my project the dependencies have the same version as the project itself (they are all artifacts of the same product).

Maven dependency for javax.mail

What is the maven dependency i should add for
import javax.mail.*;
import javax.mail.internet.*;
Adding the maven dependency from here http://mvnrepository.com/artifact/javax.mail/mail/1.5.0-b01 makes some of the jersey dependencies unable to retrieve error. What do you think is going wrong?
The version 1.6.3 had been the last version of JavaMail; since 2019-07-03, the new name for it is "Jakarta Mail".
Together with the name change also the Maven coordinates got different:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>…</version>
</dependency>
The project homepage can be found here: https://eclipse-ee4j.github.io/mail/
We are using following dependency:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>

Maven. Find versions of included dependencies by dependency

Is it possible, given a dependency such as shown below to determine the versions of included dependencies:
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.6</version>
</dependency>
For example, can we determine which version of javax.servlet-api tomcat-embed-core uses as dependency?
I would like to use the same version of javax.servlet-api in a sub-module. But I don't want to include the whole tomcat-embed-core dependency just to get the right version of javax.servlet.api.
(Optional question: Is there an easy way to do this in IntelliJ?)
In Intelij you can right click on the pom -> maven -> show effective pom.
Or I would say best is from the command line:
mvn dependency:list | grep tomcat

Override parent pom dependency

I made a simple EAR project with maven and wildfly, but I have some problems with obsolete dependencies.
Project structure is like:
Project
--EarProject
--BaseProject
--WarProject
--EjbProject
In parent Project's pom there is dependency:
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
And in BaseProject's pom I use Selenium:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</dependency>
The problem is that in BaseProject Maven libraries I see older versions of Selenium (ie. selenium-firefox-driver 2.40.0 instead of newer 2.44.0) and because of bugs in 2.40.0 my app does not work corectly.
I tried to add:
<version>2.44.0</version>
in BaseProject's pom, but I got warning like
Overriding managed version 2.40.0 for selenium-remote-driver
and it does not work.
How can I override version of dependency from parent's pom or exclude selenium from jboss-javaee-7.0-with-tools dependency?
How can I override version of dependency from parent's pom
The "Overriding managed version 2.40.0 for selenium-remote-driver" warning is a just a m2e warning not a Maven warning. With your code, you are correctly overriding the version of the dependency of the parent's pom. See this bug at Eclipse site for m2e about this warning. You can assert that by looking at the dependency tree (in Eclipse or with the mvn dependency:tree command)
or exclude selenium from jboss-javaee-7.0-with-tools dependency?
You can do that with the exclusions tag. It is a tag where you specify each groupId and artifactId that you want to exclude from the transitive dependencies resolved by Maven.

Force latest version for maven dependencies

I have the following dependency (only so far) pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.6.2.RELEASE</version>
</dependency>
This dependency obviously depends on other "dependencies" via it's pom.xml... when maven finished downloading these dependencies I noticed that it didn't grab the latest version of the Spring stuff (4.0.6.RELEASE)... it grabbed a 3.2.x version.
How can I force maven to grab the latest version of the Spring stuff? Do I need to explicitly modify my pom.xml to include all the dependencies or is there some "magic" I can use for this?
Thanks.
Spring "Bill Of Materials"
Salvation may come from special "bill of materials" POMs supported by Maven and published by Spring. Quoting from Maven "Bill Of Materials" Dependency in their manual:
It is possible to accidentally mix different versions of Spring JARs when using Maven. For example, you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release. If you forget to explicitly declare a direct dependency yourself, all sorts of unexpected issues can arise.
To overcome such problems Maven supports the concept of a "bill of materials" (BOM) dependency. You can import the spring-framework-bom in your dependencyManagement section to ensure that all spring dependencies (both direct and transitive) are at the same version.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Would this work for you?
Looking at the spring-data-jpa artifact pom file, we can see that it has a parent called spring-data-parent with current version 1.4.2.RELEASE. It's pom describes dependencies and their versions. Currently spring version is at 3.2.10.RELEASE
One way you can possibly accomplish what you want is to add explicit dependency on spring artifacts. But you would still have to define their versions.

Resources