Maven 2 & 3

Make dependencies of test-jars transitive

Details

  • Complexity:
    Intermediate
  • Number of attachments :
    1

Description

test-jar transitive dependencies are calculated as per compile scope rather than test scope.

The situation is demonstrated nicely in it0077:

  • module sub1 has a test-scoped dependency of commons-lang
  • module sub2 has a test-scoped dependency of sub1 test-jar

sub2 tests should inherit the commons-lang transitive dependency. For example:

Index: maven-core-it/it0077/sub2/src/test/java/org/apache/maven/it0077/PersonTwoTest.java
===================================================================
— maven-core-it/it0077/sub2/src/test/java/org/apache/maven/it0077/PersonTwoTest.java (revision
328307)
+++ maven-core-it/it0077/sub2/src/test/java/org/apache/maven/it0077/PersonTwoTest.java (working
copy)
@@ -1,6 +1,7 @@
package org.apache.maven.it0077;

import junit.framework.TestCase;
+import org.apache.commons.lang.BooleanUtils;

public class PersonTwoTest
extends PersonTest

Results in:

[INFO] ----------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ----------------------------------------------------------------------------
[INFO] Compilation failure

c:\maven-components\maven-core-it\it0077\sub2\src\test\java\org\apache\maven\it0077\PersonTwoTest.java:[4,31]
package org.apache.commons.lang does not exist

Issue Links

Activity

Hide
Carlos Sanchez added a comment -

Set a better title. The problem here is that by design test dependencies are not transitive

Show
Carlos Sanchez added a comment - Set a better title. The problem here is that by design test dependencies are not transitive
Hide
Kenney Westerhof added a comment -

changed the title as 'Make test dependencies transitive' is incorrect. Test dependencies
are dependencies with scope test. test-jar dependencies are something totally different,
and they can have scope compile.

Show
Kenney Westerhof added a comment - changed the title as 'Make test dependencies transitive' is incorrect. Test dependencies are dependencies with scope test. test-jar dependencies are something totally different, and they can have scope compile.
Hide
Lukas Theussl added a comment -

Attaching a simple test project as I just came across this. It doesn't cover all possible manifestations but is the simplest self-contained example that I could come up with. Running test in impl fails, uncommenting the util dependency (non test-jar) in impl's pom makes it pass. In practice I guess this bug is often masked by the fact that you also have a dependency on the corresponding main jar anyway.

Show
Lukas Theussl added a comment - Attaching a simple test project as I just came across this. It doesn't cover all possible manifestations but is the simplest self-contained example that I could come up with. Running test in impl fails, uncommenting the util dependency (non test-jar) in impl's pom makes it pass. In practice I guess this bug is often masked by the fact that you also have a dependency on the corresponding main jar anyway.
Hide
Ittay Dror added a comment -

is there a workaround? right now this means I have to copy&paste all test dependencies. (I can't separate to an independent module since test-jar depends on classes in the module and the module's test depend on the test-jar)

Show
Ittay Dror added a comment - is there a workaround? right now this means I have to copy&paste all test dependencies. (I can't separate to an independent module since test-jar depends on classes in the module and the module's test depend on the test-jar)
Hide
Didier Loiseau added a comment -

Any progress on this issue? As of 2.2.1 it does not seem to be fixed …
I have exactly the same use case than Ittay and this is very annoying as the test-jar dependencies evolve.

Show
Didier Loiseau added a comment - Any progress on this issue? As of 2.2.1 it does not seem to be fixed … I have exactly the same use case than Ittay and this is very annoying as the test-jar dependencies evolve.
Hide
William Ghelfi added a comment -

I have a (not so) slightly different use case and really would like to see this issue fixed...

Show
William Ghelfi added a comment - I have a (not so) slightly different use case and really would like to see this issue fixed...

People

Vote (46)
Watch (46)

Dates

  • Created:
    Updated: