Search code examples
eclipsemavenjunitm2eclipse

Work around for m2e workspace resolution lacking test-classes in launcher classpath when test classifier set as dependency


Does anyone know how to workaround the problem where recent M2eclipse plugins fail to include dependent projects test-classes directory in junit launcher's classpath when the test's pom lists the test as a dependency?

Steps to Rep

  • Create to pom projects providerProj, userProj
  • In providerProj create TestUtils class and store with its tests
  • Set userProj to depend on provider's test classified artifact (provider-test.jar)
  • Add userProj test which invokes TestUtils class from providerProj

On commandline all works as expected. TestUtils class found via test classpath.

  • Import projects into eclipse
  • Run userProj test as junit

failure class not found.

When we check the classpath for the test don't see providerProj/test-classes folder. If we close providerProj and rerun, it works and we see provider-test.jar on class path.

useProject
<dependency>
   <groupId>workspacetest</groupId>
   <artifactId>providerProj</artifactId>
   <classifier>test</classifier>
</dependency>

We can manually edit the launchers and add in the necessary folders but that's not ideal. I might be able to convince m2eclipse to dump src and test output into target/classes which would mask the problem and open me up for entangled code. I can fork m2eclipse and change handle to assume that test classifier dep means include workspace resolution target/test-classes.

Do you know of a solution to the problems?

Thanks

Peter


Solution

  • You need to use <classifier>tests</classifier>.

    BTW, http://maven.apache.org/guides/mini/guide-attached-tests.html discourages the use of the tests classifier, <type>test-jar</type> is preferred.