How to manage Maven2 inter-test dependencies

I have two Maven modules, A and B. Both have main and test directories.

Some of the test code in A depends on the test code in B.

When building in Maven I get the maven-jar-plugin to use the goal test-jar, which generates the test jars too. Then in module A's pom, I put a test-scoped dependency on the tests in module B:

<dependency>
    <groupId>com.myapp.package</groupId>
    <artifactId>module-B</artifactId>
    <version>1.0-SNAPSHOT</version>
    <scope>test</scope>
    <classifier>tests</classifier>
</dependency>



This works perfectly with Maven, but IntelliJ 9.0.2 has trouble with the dependencies - although the code compiles fine in IntelliJ, when I run a unit test in module A, I get a NoClassDefFoundError for the classes required from B.

Is there any way I can globally tell IntelliJ that for each module marked as a test dependency, the test sources should be included too? Any other suggestions/comments are welcome.

Many thanks
3 comments

Hi all!
I have exactly the same question!
Any clues are welcome!
Thx
J.

0

Found the answer here: http://stackoverflow.com/questions/174560/sharing-test-code-in-maven

Use

<dependency>
  <groupId>com.myco.app</groupId>
  <artifactId>foo</artifactId>
  <version>1.0-SNAPSHOT</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

instead of

<dependency>
  <groupId>com.myco.app</groupId>
  <artifactId>foo</artifactId>
  <version>1.0-SNAPSHOT</version>
  <classifier>tests</
classifier
>
  <scope>test</scope>
</dependency>

0

Please sign in to leave a comment.