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
On commandline all works as expected. TestUtils class found via test classpath.
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
I wanted to do something similar not long ago. The issue is that Eclipse and Maven handle builds differently, and right now Eclipse doesn't deal with Maven's concept of classified artifacts very well. That's a paraphrase of notes I found in this Eclipse bug report.
I was able to find a workaround so both Eclipse and Maven function. I add this to the POMs that need items from a classified jar. (Note, I did this for test resources, not test source, so you may need to adjust if I don't have the config quite right below...)
<profile>
<!-- Contents of this profile only needed to make this project work in Eclipse. -->
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>include-test-source-eclipse</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>../myOtherProj/src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Putting the build-helper plugin inside the profile ensures it only runs when in Eclipse, and not as part of a normal Maven build. It isn't pretty, but it works, at least in Eclipse Juno and m2e 1.3.1.20130219-1424.
The only issue I've had with the configuration is that sometimes Eclipse doesn't seem to find changes I made in my provider project. The fix is to run Maven --> Update Project on the provider project and any projects depending on it. I wasn't changing resources often enough for this to be a big deal for me.
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.
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