Dependency convergence error caused by maven-enforcer-plugin - maven

The following is the error I see, what confused me is that why it would depends on 2 versions of my-engine dependency. One is 0.9.0-20180510.015454-2 and another is 0.9.0-SNAPSHOT.
Heres's the command I use:
mvn clean install -DskipTests
In the pom.xml, I specify the version as ${project.version} which here should be 0.9.0-SNAPSHOT. Could you anyone help me ? Thanks
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce) # zeppelin-server ---
[WARNING]
Dependency convergence error for org.apache.hadoop:hadoop-client:2.7.3 paths to dependency are:
+-myproject:my-server:0.9.0-SNAPSHOT
+-myproject:my-engine:0.9.0-20180510.015454-2
+-org.apache.hadoop:hadoop-client:2.7.3
and
+-myproject:my-server:0.9.0-SNAPSHOT
+-myproject:my-engine:0.9.0-SNAPSHOT
+-org.apache.hadoop:hadoop-client:2.7.5
Here's the dependency in pom.xml
<dependency>
<groupId>myproject</groupId>
<artifactId>my-zengine</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>my-zengine</artifactId>
<version>${project.version}</version>
</dependency>

You could fix this in one of two ways, either choose to ignore it
mvn clean install -Denforcer.fail=false
or add both wildcard exclusion and exclusion for every dependency that caused the enforcer in the first place as follows.
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
<version>2.5.1</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
</exclusion>
</exclusions>

Related

maven cannot use correct version in verson range

I'm using maven version 3.6.2 to build my project, it has multiple layers of dependencies and finally depends on ~/.m2/repository/com/nimbusds/nimbus-jose-jwt/5.10/nimbus-jose-jwt-5.10.pom
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>[1.3.1,2.3]</version>
</dependency>
I got compile failed: com.nimbusds:nimbus-jose-jwt:jar:5.10 -> net.minidev:json-smart:jar:2.3-SNAPSHOT: Failed to read artifact descriptor for net.minidev:json-smart:jar:2.3-SNAPSHOT: Failure to find net.minidev:minidev-parent:pom:2.3-SNAPSHOT...
If I manually update ~/.m2/repository/com/nimbusds/nimbus-jose-jwt/5.10/nimbus-jose-jwt-5.10.pom to use <version>2.3</version> instead of <version>[1.3.1,2.3]</version>then it can compile fine. Why maven cannot interpret [1.3.1,2.3] correctly?
I use this to solve the program, refer https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/388/json-smart-pom-23-snapshot
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>5.10</version>
<!--参考https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/388/json-smart-pom-23-snapshot-->
<exclusions>
<exclusion>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
</dependency>

Why isn't maven including a needed transitive dependency?

I am converting our Jenkins Freestyle build to Declarative Pipeline mode. I am using the same POM files.
But whenever i run the pipeline build, i see that the desired war is missing a transitive dependency. The Freestyle build includes that missing dependency however.
The Main parent POM includes:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
The second parent includes section below, :
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
</dependencies>
For both build processes, the dozer artifact is contained in the war file. But dozer contains a dependency of its own:
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
It is this commons-beanutils that I am missing from my final war when i do the Pipeline build. Since I am using the same POM files for both build processes, how can this be possible?
Please help

Override version of transitive dependencies in Maven

I have the following in my pom
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>org.codehaus.groovy</artifactId>
<groupId>groovy-all</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>org.codehaus.groovy</artifactId>
<groupId>groovy-all</groupId>
</exclusion>
</exclusions>
</dependency>
Basically, I want to force my second and third dependencies to use the version of groovy-all that I'm setting in my first dependency. Is there a better way to do this than setting an exclusion on each of them?
Since as a first dependency you're explicitly defining a version of the groovy-all dependency, this will override the version of this dependency for all transitive dependencies needing this exact dependency. Hence, you won't have to define explicit exclusions.
To validate this, you can run the following before and after the change:
mvn dependency:tree -Dverbose
And compare the output.
Fix is to lock down the version, either via a direct dependency, or a dependency-management section.

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>

Maven dependency picocontainer

I'm trying to include with maven dependency for
<dependency>
<groupId>org.jacorb</groupId>
<artifactId>jacorb</artifactId>
<version>2.3.1</version>
</dependency>
Dependency is resolved, but it's causing problem with another dependency, picocontainer:
[ERROR] Failed to execute goal on project s_s: Could not resolve dependencies
for project my.package:s_s:war:1: Failed to collect dependencies for org.jacorb:jacorb:jar:2.3.1 (compile), picocontainer:picocontainer:jar:1.2 (compile)]: Failed to read artifact descriptor for picocontainer:picocontainer:jar:${picocontainer.version}: Could not transfer artifact picocontainer:picocontainer:pom:${picocontainer.version} from/to central (http://repo.maven.apache.org/maven2): IllegalArgumentException: Illegal character in path at index 65: http://repo.maven.apache.org/maven2/picocontainer/picocontainer/${picocontainer.version}/picocontainer-${picocontainer.version}.pom -> [Help 1]
When I check local repo, version named ${picocontainer.version} is created. I've tried include own dependency:
<dependency>
<groupId>picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>1.2</version>
</dependency>
But it's not helping, could someone help me out?
OK I figured it out :) I ought to exclude dependency from org.jacorb like this:
<dependency>
<groupId>org.jacorb</groupId>
<artifactId>jacorb</artifactId>
<version>2.3.1</version>
<exclusions>
<exclusion>
<groupId>picocontainer</groupId>
<artifactId>picocontainer</artifactId>
</exclusion>
<exclusion>
<groupId>picocontainer</groupId>
<artifactId>picocontainer-tck</artifactId>
</exclusion>
<exclusion>
<groupId>picocontainer</groupId>
<artifactId>picocontainer-gems</artifactId>
</exclusion>
</exclusions>
</dependency>
And include necessary one
<dependency>
<groupId>picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>picocontainer</groupId>
<artifactId>picocontainer-tck</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>picocontainer</groupId>
<artifactId>picocontainer-gems</artifactId>
<version>1.2</version>
</dependency>
I guess it's maven corrupted artifact?

Resources