I'm trying to make sure my test-jar published from maven has the right transitive dependencies.
The test-jar doesn't, for instance, generate with a dependency on the non-test-jar.
Similarly, say AAA publishes a test-jar, and BBB contains a test-scoped dependency for AAA's test-jar. In CCC's tests, when I use a class from BBB's test-jar that uses a class from AAA's test-jar, I get a 'class not found' error on the class from AAA's test-jar - i.e., BBB's tests' transitive dependencies aren't properly recorded at all.
Is there any way to make depending on BBB's test jar properly pull in transitive dependencies?
I have example code for all this in https://github.com/nkronenfeld/transitive-test-dependencies
There are two commented-out dependencies in CCC/pom.xml for the BBB's normal jar, and AAA's test-jar, neither of which seem like they should be needed. CCC's test goal won't however, run without either.
As khmarbaise said: Test dependencies are not transitive. If A declares a test dependency on B, this means that A needs B to run its tests. Users of A do not need to know about this. If a test-jar needs something to run, it should declare a compile dependency on this.
I ran into this same issue. In my case, I had stub classes in project A, stub classes in project B which depended on A's stub classes, and then I wanted to use B's stub classes in project C.
I think the "right" way to attack this problem is to create two additional projects: A-stubs and B-stubs:
compile
scope).test
scope.test
scope.test
scope.With that in place, the transitive dependencies of B-stubs should be handled just fine. You shouldn't need to build any test JARs at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With