Hi!


I'm using the test-jar mechanism to share common classes for tests, between different modules of a larger project. The main idea is to do database and server start-ups in the common classes, but avoid distributing them in the main JARs.

To do this I have followed the guide at http://maven.apache.org/ guides/mini/guide-attached-tests.html

However I have discovered a behaviour that I'm not sure if is intentional or not.

See a dummy test-project at http://soiland.no/testjars.zip

Note that you do have to use "mvn install" and not "mvn test" - otherwise module2 won't be able to find the non-installed module 1 test-jar. (It would of course be great if "mvn test" also worked in this case, but this is not my main concern)



Most notably you will notice a main project with module1, 2, 3a, 3b and 3c, each of which contain a single class sub-classing the one from the previous module, this forming dependencies.


Module 1, 2 and 3c expose their test classes using:

                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-jar-plugin</artifactId>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>test-jar</goal>
                                                </goals>
                                        </execution>
                                </executions>
                        </plugin>


module 2 depends on the module 1 test classes for the scope test:

                <dependency>
                        <groupId>no.soiland.test.testjars</groupId>
                        <artifactId>module1</artifactId>
                        <version>0.0.1</version>
                        <type>test-jar</type>
                        <scope>test</scope>
                </dependency>

This works perfectly.



Just as modules 3(a,b,c) depend on module 2:

                <dependency>
                        <groupId>no.soiland.test.testjars</groupId>
                        <artifactId>module2</artifactId>
                        <version>0.0.1</version>
                        <type>test-jar</type>
                        <scope>test</scope>
                </dependency>

(Notice that junit depencies are not affected in this particular case because they are stated for all the modules in the parent POM with scope "test")



However, in module 3a I also need to include the dependencies to the transitive dependency module1. Module 3b shows a variant which just depends on module2 and fails to build.

[INFO] Compiling 1 source file to /Users/.stain/unencrypted/workspace/ testjars/module3b/target/test-classes [INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

/Users/.stain/unencrypted/workspace/testjars/module3b/src/test/java/ no/soiland/test/testjars/module3b/Module3bTest.java:[8,7] cannot access no.soiland.test.testjars.module1.Module1Test
file no/soiland/test/testjars/module1/Module1Test.class not found
public class Module3bTest extends Module2Test {



I've tried in module 3c to include the test-jar build target for consistency with module 2, but the same error occurs.


So the problem is that module 3b won't pick up that module 2's test jar also requires module 1's test jar. However, if I in module 2's pom remove <scope>test</scope> everything works. I believe this is because module 2's test-jar depends on module 2's jar (and thereby module 2's dependencies). I don't think this is a very good solution as this forces any module2-users to also depend on the module 1 tests. Hard-coding the module 1 test dependency as in module 3a also works, but it means that the dependencies have to be copied over manually whenever module 2 is updated.

The deployed POMs does include the test-jar dependencies, so Maven should be able to pick this up. I'm not sure if it should, but I guess it would be highly likely that if some dependency is needed to compile or run a test, then it would also be needed for artefacts depending on those tests.


Note: I have not tested this with other <scope>test</scope> dependencies that are normal JARs.





Is this a bug or am I just attacking this issue the wrong way? Any suggestions welcome :-)

--
Stian Soiland, myGrid team
School of Computer Science
The University of Manchester
http://www.cs.man.ac.uk/~ssoiland/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to