Parent POM's managed version not respecting version - maven

I have a parent pom with a managed dependency that looks like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
<version>1.0.7</version>
</dependency>
I have a submodule with that uses that dependency. The pom entry looks like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
</dependency>
However the compile failed. When I looked at the effective pom for the submodule the entry looked like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
<version>1.0.6</version>
</dependency>
I've looked for something transitive but this is a top level dependency and is only coming in from a single place.
I ran mvn dependency:analyze-dep-mgt but it reported no issues.
Any and all suggestions will be greatly appreciated.

A colleague had done a merge which changed the artifactId in the parent pom. This resulted in the unexpected state.

Related

Maven groovy-all change versions

I have dependency in pom with groovy-all
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.7</version>
<type>pom</type>
</dependency>
But if I check libs inside, I see 2.5.13 versions. How can I change all of this libs to 3.0.7? Of course I can add separately, but maybe is another option?
The versions are managed in the <dependencyManagement> section of the POM, either directly or by using a BOM (scope import).
If you want to update them, you need to look there.
You are importing Groovy 2.5.13 elsewhere likely as a transitive dependency and maven is deciding to use 2.5.13 instead of 3.0.7.
Look at the groovy 3.0.7 pom:
https://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/3.0.7/groovy-all-3.0.7.pom
It has no reference to 2.5.13.

upgrade inherit maven dependencies from parent pom

in spring boot project tomcat-embed-core: 9.0.12 is getting resolved by parent dependency spring-boot-starter-web:2.1.0.
but due to some reasons we have to upgrade the tomcat-embed-core version from 9.0.12 to 9.0.20.
I have added the below dependency separately in POM,
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.20</version>
</dependency>
now I can see V9.0.20 in dependency hierarchy, but also omitted for conflict with 9.0.20.
is this a correct way, if no then suggest the best way to do this?

Maven: using a dependency version as a property across different modules

I have got a project with a number of modules in it, now, e.g. I have a module M1 and its version 1.0.0 and in the same project I have got 8 other modules in which I have M1 as a dependency.
The problem is when I make a change in M1, update version to 1.0.1 and upload it to central repo, I have to change that version number 8 times.
I want to use this version number as property, which I have tried to put it as as a prop in parent pom but a maven warning saying its not right to do...
any thoughts? thanks in advance
Don't define the version as a property.
Adjust the <dependencyManagement> section in the parent pom like below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.yourGroup</groupId>
<artifactId>M1</artifactId>
<version>1.0.1</version>
</dependency>
<!-- eventually more dependencies -->
</dependencies>
</dependencyManagement>
In the 8 modules which depend on M1, insert:
<dependency>
<groupId>com.yourGroup</groupId>
<artifactId>M1</artifactId>
</dependency>
Take a look at the POM Reference - Dependency Management for further knowledge

Gradle cannot resolve dependency

In my build.gradle file I have a line in dependencies:
compile group: 'org.jboss.seam.validation', name: 'seam-validation-api', version:'3.1.0.Final'
When I try to run the project, e.g. 'test' task, I get an error:
> Could not resolve org.jboss.seam.validation:seam-validation-api:3.1.0.Final.
Required by:
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT > com.smspl.mc5:mc5-common-rest:1.0.0-SNAPSHOT
> Could not parse POM /Users/amorfis/.m2/repository/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
> Could not parse POM https://nexus.softwaremill.com/content/groups/smlcommon-repos/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
I'm aware that the problem is that version of 'javax.enterprise:cdi-api:jar' is not specified in the seam-validation-api pom. It is specified in it's parent, and gradle probably has some problems figuring it out. The parent part of seam-validation-api pom looks like this:
<parent>
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<version>3.1.0.Final</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
My gut feeling tells me the problem is in part. I also tried to add this parent dependency explicitely, by adding new line to build.gradle 'dependencies', but without any luck.
Anyone knows solution to this?
UPDATE: In the parent pom:
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<packaging>pom</packaging>
<version>3.1.0.Final</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-bom</artifactId>
<version>${seam.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is a little research of the problem (only research, NOT a solution):
seam-validation-api-3.1.0.Final.pom has parent seam-validation-parent-3.1.0.Final.pom
seam-validation-parent-3.1.0.Final.pom has parent seam-parent-19.pom
The file seam-parent-4.pom contained version definition for cdi-api, but seam-parent-19.pom does not.
The file seam-validation-parent-3.0.0.Final.pom did contain dependencyManagement for cdi-api, but newer version seam-validation-parent-3.1.0.Final.pom does not.
I also looked into the code of GradlePomModuleDescriptorBuilder (the class that throws the abovementioned "Could not resolve..." exception). It seems that the class looks for DependencyManagement sections up the parent-pom chain, but it does not respect resolutionStrategy (or any other definitions from gradle script). So currently it is not possible to augment/override dependencyManagement of POM.
My advice: contact the developer(s) of seam framework and ask them to fix the dependencies.

Adding POM type dependency using m2eclipse, unable to resolve

I am trying to add Hector dependencies to my POM. My IDE is Eclipse, and I am also using m2eclipse. Adding dependencies of JAR type is not a problem, but this dependency is of type POM. I have tried almost everything usual including cleaning, building, and using import scope but nothing seem to have helped. When I try to add import me.prettyprint.hector.api.Serializer;
I get the error "The import cannot be resolved".
Is there anything else I need to do to use POM type dependencies or is there a better way of using dependencies of POM types in the project?
I believe his question is not as obvious as simply including the necessary dependency. I have experienced this problem too and am looking for a solution. The problem can be clearer stated as the following:
Let's say I have two maven projects (project A and project B). Project A is a simple web-app which wants to include dependencies as stated in project B. However, project B packaging type is "pom". This should allow all of project B's dependencies to be included into project A. Here is an example:
Project A (packaging is "war"):
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
</dependencies>
Project B (packaging is "pom")
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
What we'd like to see in Eclipse is when you run maven eclipse:eclipse on Project A, that you can see the commons-lang-2.4.jar file as a dependency under project A such that you can resolve it in your code when imported. This is not happening and I'm still looking for such a solution.
The error indicates that the relevant class is missing in your classpath. A search of this class indicates, it is available in hector-core
This discussion indicates how this dependency can be imported, viz. adding the following entry to your project pom (or choosing this appropriately in m2eclipse).
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
<version>0.7.0-29</version>
</dependency>

Resources