Daniel Lipsitt created MNG-5449:
-----------------------------------
Summary: Conflicting dependencies and NoClassDefFoundError
Key: MNG-5449
URL: https://jira.codehaus.org/browse/MNG-5449
Project: Maven 2 & 3
Issue Type: Bug
Components: Artifacts and Repositories, Dependencies
Affects Versions: 3.0.4
Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
Java version: 1.6.0_37, vendor: Apple Inc.
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.6.8", arch: "x86_64", family: "mac"
Reporter: Daniel Lipsitt
h3. Overview
I have conflicting transitive dependencies that lead to a runtime
{{NoClassDefFoundError}} without any warning.
h3. Details
I have a project whose transitive dependencies include two versions of
{{org.apache.maven/maven-artifact}}, 3.0.4 and 2.2.1.
{code:xml|title=pom.xml}
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<type>maven-plugin</type>
</dependency><dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-generators</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
</project>
{code}
These artifacts have conflicting transitive dependencies:
{code}
$ mvn dependency:tree -Dverbose -Dincludes=org.apache.maven:maven-artifact
[INFO] demo:demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.antlr:antlr4-maven-plugin:maven-plugin:4.0:compile
[INFO] | +- org.apache.maven:maven-plugin-api:jar:3.0.4:compile
[INFO] | | \- org.apache.maven:maven-artifact:jar:3.0.4:compile
[INFO] | \- org.apache.maven:maven-project:jar:2.2.1:compile
[INFO] | +- org.apache.maven:maven-artifact-manager:jar:2.2.1:compile
[INFO] | | \- (org.apache.maven:maven-artifact:jar:2.2.1:compile - omitted
for conflict with 3.0.4)
[INFO] | \- (org.apache.maven:maven-artifact:jar:2.2.1:compile - omitted
for conflict with 3.0.4)
[INFO] \-
org.apache.maven.plugin-tools:maven-plugin-tools-generators:jar:3.2:compile
[INFO] +-
org.apache.maven.plugin-tools:maven-plugin-tools-api:jar:3.2:compile
[INFO] | \- (org.apache.maven:maven-artifact:jar:2.2.1:compile - omitted
for conflict with 3.0.4)
[INFO] \- org.apache.maven:maven-plugin-descriptor:jar:2.2.1:compile
[INFO] \- (org.apache.maven:maven-artifact:jar:2.2.1:compile - omitted
for conflict with 3.0.4)
{code}
Here's some simple code importing a class from one of the direct dependencies:
{code:java|title=Main.java}
package demo;
import org.apache.maven.tools.plugin.generator.GeneratorUtils;
public class Main {
public static void main(String[] args) {
System.out.println(GeneratorUtils.toText("{@code demo}"));
}
}
{code}
When run, it gives the following traceback:
{code}
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/maven/artifact/DependencyResolutionRequiredException
at demo.Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException:
org.apache.maven.artifact.DependencyResolutionRequiredException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
{code}
It turns out that {{DependencyResolutionRequiredException}} is present in
maven-artifact 2.x, but not in 3.x.
Given the above, I would have expected a warning of some kind about the
conflicting transitive dependencies if they can't be resolved automatically.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira