Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349616 - Project build output from src/test/resources is added to Java classpath for non-test executions
Summary: Project build output from src/test/resources is added to Java classpath for n...
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-16 15:20 EDT by Jonathan Cone CLA
Modified: 2021-04-19 13:24 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Cone CLA 2011-06-16 15:20:30 EDT
Build Identifier: Helios SR 2 20110218-0911

Resource files from test subfolders are leaking across the classpath when Java programs are run from the IDE.

M2E Version: 0.12.1.20110112-1712

Reproducible: Sometimes

Steps to Reproduce:
1. Create a workspace with two projects.
2. In Project A, create a resource test.properties in src/test/resources
3. In Project B, create a resource test.properties in src/main/resources
4. Define the property 'foo' in both files, but give it a different value in each.
5. Make Project A dependent upon Project B.
6. Build the projects.
7. Check the build output.
8. Create a trivial Java class with a main method that reads the property from the file.

For some reason, the build output may contain test.properties from Project B, instead of Project A.  In this case, executing the program from step 7 will return the wrong property value.

This only causes a problem when the dependent project is open in the workspace.  Otherwise, it works correctly.  This is causing a problem for projects that have property files which override other property files for testing purposes.  For example, hibernate.cfg.xml, etc.
Comment 1 Jonathan Cone CLA 2011-06-16 15:37:59 EDT
Note, the test case provided is contrived to illustrate the problem.  This is occurring for a web application with multiple projects.  When the application is deployed to Tomcat using WTP, its picking up the wrong properties from resources in the test folder subtree of dependent projects.
Comment 2 Igor Fedorenko CLA 2011-06-16 16:25:16 EDT
Please attach complete standalone sample project and provide steps to reproduce the problem. 

FYI, expected runtime and test runtime classpath is described in [1]. I am not aware of any problems in this area and unit test coverage is pretty good actually [2].


[1] https://docs.sonatype.org/display/M2ECLIPSE/Runtime+classpath
[2] https://github.com/sonatype/m2e-core-tests/blob/master/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/ClasspathProviderTest.java
Comment 3 Steve Ash CLA 2011-08-13 01:48:43 EDT
(In reply to comment #2)

Igor in [1] does it only ever use src/test/resources or does it inspect the test-resources configuration in the POM? to determine which things to place _before_ the src/main things when building the classpath?

For example, we have addition resources and test-resources folders:
src/main/config
src/test/config

and would like the test/config to override main/config -- this doesn't seem to be respected right now -- but I haven't nailed down whether the problem is a consequence of the JDT issue you refer to in [1] or not.
Comment 4 Igor Fedorenko CLA 2011-08-13 02:42:46 EDT
m2e uses test source and resource folders as configured in pom.xml.

All test sources and resources get compiled to the same test output folder (i.e. target/test-classes by the default) and this output folder is expected to be placed on test runtime classpath before main output folder when the user utn tests using RunAs->JUnitTest on a Maven project or one of its resources.

m2e injects special classpath provider, i.e. logic that calculates runtime classpath, into RunAs->JUnitTest (always) and RunAs->JavaApplication (when it can detect the main class comes form test source folder) launch configurations associated with Maven projects. m2e core does not apply test classpath calculation logic to other launch configuration types, but you need to ask m2e-wtp developers if there is Maven test classpath support in m2e-wtp.
Comment 5 Steve Ash CLA 2011-08-13 03:09:13 EDT
Thanks for the reply Igor.  I know that the author of this bug was referring to WTP but my question was specifically about the java launch profile so thanks for the answer.  So I need to do a little more digging to find out the source of my problem as (per your description) this shouldn't be a problem.  What I _do_ notice is that if I re-arrange my source folders (which src/test/resources, src/main/resources, etc. are all source folders) in the Project -> Exports so that they are ordered as:

src/test/resources
src/test/config
src/test/java
src/main/resources
src/main/config
src/main/java

then everything works -- however, after running maven -> update project configuration, m2e re-orders the source folder exports as:

src/main/resources
src/main/config
src/main/java
src/test/resources
src/test/config
src/test/java

and now it doesn't work.  I have to go manually "revert" the .classpath file from svn to re-apply my original ordering.  I wouldn't care of course about what order is in the eclipse project configuration so long as the run configuration classloader looked up as described in your description.

(specifically i am oredering them like this because i have a "test time" properties file in src/test/config that overrides a file of the same name with my prod values in src/main/confg)

Sorry I don't mean to hijack this bug with my problem, but it seemed relevant.
Comment 6 Igor Fedorenko CLA 2012-05-21 11:15:47 EDT
Closing old/stale bugreports.
Comment 7 Denis Roy CLA 2021-04-19 13:24:21 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/