1

I'm trying to use a test-jar dependency in another maven module during testing. So just like in this question (Maven test dependency in multi module project) and in the maven guides, I placed a test-jar goal in module A, and put a dependency on it in module B where I want to use some classes from A in my testing. Eclipse recognizes all my classes properly, and when I run a clean install from my project root, then run mvn dependency:tree in module B, I see module A.

However, when I run a mvn clean install, maven complains that

... package 'my.package.in.module.A' does not exist

Structure of my project is

reactor
--module A
--module B

Pom A:

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

Pom B:

 ...
<dependency>
  <groupId>com.company.moduleA</groupId>
  <artifactId>module-A</artifactId>
  <version>moduleA-version</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

I left out the version/artifact/etc for privacy, but they match up properly.

Am I missing something?

EDIT: This is maybe not the right solution to this question in particular, but I just removed the <type>test-jar</type> and got it working without using that.

Community
  • 1
  • 1
eipark
  • 7,442
  • 3
  • 24
  • 33
  • 2
    In all things Maven ... a POM speaks a thousand words. – Perception Apr 11 '13 at 13:30
  • You commented too quickly... the POM was coming :) – eipark Apr 11 '13 at 13:34
  • That all seems correct. ... And the reactor's `pom.xml` has a proper `` section...? Are you sure there isn't a cyclic dependency between A and B? – carlspring Apr 11 '13 at 14:44
  • Has modules section and no cyclic dependency. – eipark Apr 11 '13 at 14:50
  • @eipark Can you provide more context around the "does not exist" message? What phase / goal does this occur in? Have you tried running with `-X`? – Peter Mularien Apr 11 '13 at 15:31
  • Is Maven actually installing the artifact locally and then in the remote repository? Can you verify that this exists in your local repo at the time of failure? – carlspring Apr 11 '13 at 16:15
  • It says `Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3:testCompile.......Compilation failure`. I see the test jar in the Module A target. – eipark Apr 11 '13 at 16:26
  • As your edited by removing the `test-jar` and it worked. Dose that missing class place at `src/main/java` or `src/test/java` of the Module A? – Charlee Chitsuk Apr 12 '13 at 01:29

1 Answers1

7

There is a workaround. Use -DskipTests instead maven.test.skip. The second one also skips the compilation of the tests so the test-jars aren't being created.

See http://maven.apache.org/plugins/maven-surefire-plugin/examples/skipping-test.html