Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333217

Summary: test-source/resources must have first position in the build path then main-source/resources
Product: z_Archived Reporter: Andreas Höhmann <andreas.hoehmann>
Component: m2eAssignee: Project Inbox <m2e.core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: aeris+eclipse, igor, sebtardif
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Andreas Höhmann CLA 2010-12-26 13:11:28 EST
I think this is the "normal" maven style for "mvn test-compile".

A little example:

src/main/java/de.ahoehma.m2e.test.Foobar.java
src/main/resources/log4.xml
src/test/java/de.ahoehma.m2e.test.FoobarTest.java
src/test/resources/log4.xml

main log4j.xml define loglevel error
test log4j.xml define loglevel debug

If I run the tests with eclipse I would prefer to find the test-log4j before the main-log4j in the classpath/buildpath.

mvn test-compile log this:

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ test
---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-compiler-plugin:2.3.2:te
stCompile from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-com
piler-plugin:2.3.2, parent: ClassRealm[maven.api, parent: null]]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-compiler-plugin:2.3.2:t
estCompile' with basic configurator -->
[DEBUG]   (f) basedir = F:\ws_m2eclipse\test
[DEBUG]   (f) buildDirectory = F:\ws_m2eclipse\test\target
[DEBUG]   (f) classpathElements = [F:\ws_m2eclipse\test\target\test-classes, F:\
ws_m2eclipse\test\target\classes]
[DEBUG]   (f) compileSourceRoots = [F:\ws_m2eclipse\test\src\test\java]
[DEBUG]   (f) compilerId = javac
[DEBUG]   (f) debug = true
[DEBUG]   (f) failOnError = true
[DEBUG]   (f) fork = false
[DEBUG]   (f) generatedTestSourcesDirectory = F:\ws_m2eclipse\test\target\genera
ted-sources\test-annotations
[DEBUG]   (f) optimize = false
[DEBUG]   (f) outputDirectory = F:\ws_m2eclipse\test\target\test-classes
[DEBUG]   (f) outputFileName = test-0.0.1-SNAPSHOT
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@37f8d244
[DEBUG]   (f) showDeprecation = false
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) source = 1.5
[DEBUG]   (f) staleMillis = 0
[DEBUG]   (f) target = 1.5
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --
[DEBUG] Using compiler 'javac'.
[DEBUG] Source directories: [F:\ws_m2eclipse\test\src\test\java]
[DEBUG] Classpath: [F:\ws_m2eclipse\test\target\test-classes
 F:\ws_m2eclipse\test\target\classes]
[DEBUG] Output directory: F:\ws_m2eclipse\test\target\test-classes

The classpath contains first the test-classes then the classes ...

It's easy to fix this "problem":

In org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.addProjectSourceFolders(IClasspathDescriptor, ProjectConfigurationRequest, MavenProject, IProgressMonitor) we have to change the order of mavenProject.getTestCompileSourceRoots()/mavenProject.getBuild().getTestResources() and mavenProject.getCompileSourceRoots()/mavenProject.getBuild().getResources().
Comment 1 Igor Fedorenko CLA 2011-06-29 01:30:20 EDT
Please provide complete standalone example project and steps to reproduce the problem

FWIW, m2e is already expected to "inject" correct runtime classpath when RunAs->Java_Application and RunAs->JUnit_Test. Expected runtime classpath for application and tests is documented in [1] and I am not aware of any problems in this area.


[1] https://docs.sonatype.org/display/M2ECLIPSE/Runtime+classpath
Comment 2 Nicolas Vinot CLA 2011-08-05 14:56:05 EDT
This is a problem with external plugins which want to run tests, like Infinitest.
See https://github.com/infinitest/infinitest/issues/53
Comment 3 Igor Fedorenko CLA 2011-08-05 15:11:41 EDT
Test sources and resources are only part of the problem, test dependencies are equally important. The only way Infinitest can have correct Maven test classpath is by using special runtime classpath resolution logic implemented. m2e-dev is a good place to discuss possible ways to make this happen.
Comment 4 Igor Fedorenko CLA 2012-05-21 11:31:36 EDT
Closing old/stale bugreports.
Comment 5 Andreas Höhmann CLA 2012-05-23 16:36:22 EDT
ack
Comment 6 Denis Roy CLA 2021-04-19 13:27:08 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/