Maven 2 & 3

dependencies with classifier mask transitive dependencies of same dependency without classifier

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 2.0.1
  • Fix Version/s: None
  • Labels:
    None
  • Complexity:
    Expert
  • Number of attachments :
    0

Description

A module in cocoon has following dependencies :

<dependency>
<groupId>org.apache.cocoon</groupId>
<artifactId>cocoon-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cocoon</groupId>
<artifactId>cocoon-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>

The first dependency is created by the core module using :

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>

Now i would like the module to depend on the jar with classifier "tests" during the testing phase ie cocoon-core-2.2.0-SNAPSHOT-tests.jar, and during the normal compilation phase it should just use cocoon-core-2.2.0-SNAPSHOT.jar. IMO above dependencies express exactly this.

The problem is that maven somehow removes all transitive dependencies from cocoon-core-2.2.0-SNAPSHOT.jar when both dependencies are in place, breaking compilation. When i remove the dependency with the classifier, then all is fine (but ofcourse my tests can't run)

I hope above is clear, otherwise just ping me on irc

Issue Links

Activity

Hide
Carlos Sanchez added a comment -

You should use <type>test-jar</type> instead of classifier, see http://maven.apache.org/guides/mini/guide-attached-tests.html

Show
Carlos Sanchez added a comment - You should use <type>test-jar</type> instead of classifier, see http://maven.apache.org/guides/mini/guide-attached-tests.html
Hide
Jorg Heymans added a comment -

even when using test-jar it does not behave as it should.

In cocoon we have exactly this case eg here : http://svn.apache.org/repos/asf/cocoon/trunk/blocks/cocoon-midi/cocoon-midi-impl/pom.xml

When i comment out the test dependencies that are normally passed on transitively by cocoon-core i get :

powerbook:~/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl jheymans$ mvn -s ../../../settings.xml clean install
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building midi Block Implementation
[INFO] task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target
[INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/classes
[INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/test-classes
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 5 source files to /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 2 source files to /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException: org/custommonkey/xmlunit/Diff; nested exception is java.lang.NoClassDefFoundError: org/custommonkey/xmlunit/Diff
java.lang.NoClassDefFoundError: org/custommonkey/xmlunit/Diff
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2365)
at java.lang.Class.getMethod0(Class.java:2611)
at java.lang.Class.getMethod0(Class.java:2620)
at java.lang.Class.getMethod(Class.java:1579)
at org.apache.maven.surefire.junit.JUnitTestSet.createInstanceFromSuiteMethod(JUnitTestSet.java:173)
at org.apache.maven.surefire.junit.JUnitTestSet.constructTestObject(JUnitTestSet.java:137)
at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(JUnitTestSet.java:244)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:101)
at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:147)
at org.apache.maven.surefire.Surefire.run(Surefire.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Sat May 27 09:17:45 CEST 2006
[INFO] Final Memory: 6M/20M
[INFO] ------------------------------------------------------------------------

I find it strange that the tests compile but somehow don't run. I tried with both 2.0.4 and 2.0.5-snapshot.

Show
Jorg Heymans added a comment - even when using test-jar it does not behave as it should. In cocoon we have exactly this case eg here : http://svn.apache.org/repos/asf/cocoon/trunk/blocks/cocoon-midi/cocoon-midi-impl/pom.xml When i comment out the test dependencies that are normally passed on transitively by cocoon-core i get : powerbook:~/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl jheymans$ mvn -s ../../../settings.xml clean install [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building midi Block Implementation [INFO] task-segment: [clean, install] [INFO] ---------------------------------------------------------------------------- [INFO] [clean:clean] [INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target [INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/classes [INFO] Deleting directory /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/test-classes [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] Compiling 5 source files to /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] Compiling 2 source files to /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: /Users/jheymans/src/cocoon-trunk/blocks/cocoon-midi/cocoon-midi-impl/target/surefire-reports org.apache.maven.surefire.booter.SurefireExecutionException: org/custommonkey/xmlunit/Diff; nested exception is java.lang.NoClassDefFoundError: org/custommonkey/xmlunit/Diff java.lang.NoClassDefFoundError: org/custommonkey/xmlunit/Diff at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2365) at java.lang.Class.getMethod0(Class.java:2611) at java.lang.Class.getMethod0(Class.java:2620) at java.lang.Class.getMethod(Class.java:1579) at org.apache.maven.surefire.junit.JUnitTestSet.createInstanceFromSuiteMethod(JUnitTestSet.java:173) at org.apache.maven.surefire.junit.JUnitTestSet.constructTestObject(JUnitTestSet.java:137) at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(JUnitTestSet.java:244) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:101) at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:147) at org.apache.maven.surefire.Surefire.run(Surefire.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747) [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] There are test failures. [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12 seconds [INFO] Finished at: Sat May 27 09:17:45 CEST 2006 [INFO] Final Memory: 6M/20M [INFO] ------------------------------------------------------------------------ I find it strange that the tests compile but somehow don't run. I tried with both 2.0.4 and 2.0.5-snapshot.
Hide
mollusk added a comment - - edited

I have the same problem , but only on unix platform
test-jar dependencies work fine on windows

it seems that the problem comes from maven-jar-compiler, because the depencies are in maven.compile.classpath

as a work arround , i launch javac ant task before the compile phase

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2-SNAPSHOT</version>
<executions>
<execution>
<id>ant.compile-source</id>
<phase>process-sources</phase>
<configuration>
<tasks >
<echo message="compilation using ant" />
<mkdir dir="target/classes" />
<javac
destdir="target/classes"
srcdir="src/main/java"
source="1.5"
target="1.5">
<classpath refid="maven.compile.classpath" />
</javac>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</plugin>

Show
mollusk added a comment - - edited I have the same problem , but only on unix platform test-jar dependencies work fine on windows it seems that the problem comes from maven-jar-compiler, because the depencies are in maven.compile.classpath as a work arround , i launch javac ant task before the compile phase <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.2-SNAPSHOT</version> <executions> <execution> <id>ant.compile-source</id> <phase>process-sources</phase> <configuration> <tasks > <echo message="compilation using ant" /> <mkdir dir="target/classes" /> <javac destdir="target/classes" srcdir="src/main/java" source="1.5" target="1.5"> <classpath refid="maven.compile.classpath" /> </javac> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </plugin>
Hide
Christian Ziech added a comment -

We have the same problem as the Creator - I had a look at the maven source already and the problem seems to be that in the DefaultPluginManager.checkMissingArtifactsInReactor() method the dependencies resolved from the reactor are put in a HashSet - in the described case we have two dependencies for the same project. One for the main jar and one for the tests jar. Since both reference the same project this will result in only one entry being in the HashSet.
Therefor the method return value indicates that not all dependencies could be resolved, which is wrong in that case.

Show
Christian Ziech added a comment - We have the same problem as the Creator - I had a look at the maven source already and the problem seems to be that in the DefaultPluginManager.checkMissingArtifactsInReactor() method the dependencies resolved from the reactor are put in a HashSet - in the described case we have two dependencies for the same project. One for the main jar and one for the tests jar. Since both reference the same project this will result in only one entry being in the HashSet. Therefor the method return value indicates that not all dependencies could be resolved, which is wrong in that case.
Hide
Kris Nuttycombe added a comment -

This problem has ramifications beyond the scope of testing dependencies; a common scenario for the use of classifiers is in artifacts that are built for specific deployment environments which contain configuration files specific to those environments (in my case, war and ear files). In my case, I had hoped to specify an environment property in a profile, the value of which would be used for the classifier of each module in a multi-module project; the environment is also used for the selection of a filter file to use.

The lack of transitive dependencies with classifiers means that my modules cannot properly declare dependencies on one another, as the transitive dependencies of the modules being depended upon are ultimately excluded from the final artifact.

Show
Kris Nuttycombe added a comment - This problem has ramifications beyond the scope of testing dependencies; a common scenario for the use of classifiers is in artifacts that are built for specific deployment environments which contain configuration files specific to those environments (in my case, war and ear files). In my case, I had hoped to specify an environment property in a profile, the value of which would be used for the classifier of each module in a multi-module project; the environment is also used for the selection of a filter file to use. The lack of transitive dependencies with classifiers means that my modules cannot properly declare dependencies on one another, as the transitive dependencies of the modules being depended upon are ultimately excluded from the final artifact.
Hide
Stefan Alfons Tzeggai added a comment -

So there will never be transitive test/classifier dependencies in maven?

Show
Stefan Alfons Tzeggai added a comment - So there will never be transitive test/classifier dependencies in maven?

People

Vote (12)
Watch (10)

Dates

  • Created:
    Updated:
    Resolved: