Can I get eclipse (using maven, m2e) to trigger an error / warning when the main code refers to the test code?

I am using Eclipse (4.2 Juno) with m2e with default settings. The source code is in src/main/java, and the test code is in src/test/java.

Sometimes I inadvertently do importsome things from test to class mostly. Eclipse does not complain about it (both src/main/javaand src/test/javasimply configured as source folders using m2e), and all tests are run properly, because the test environment (JUnit) can get access to the code of the main and test. However, when I try to run the main code myself later (after it was supposedly checked), I will inevitably get a bunch ClassNotFoundExceptionwhen I try to use the code.

Is there a way to make Eclipse show errors or warnings when this happens?

+5
source share
2 answers

If your code in src/main/javarefers to code in src/test/java, it simply will not compile with Maven. No need to write your own compliance rule.

0
source

Unfortunately, there is no way to do this (which I know). m2e also misuses the classpath in other ways, so you should get used to running the Maven assembly before registering - regardless of what Eclipse says about compiling the code.

. http://www.eclipsecon.org/europe2012/sites/eclipsecon.org.europe2012/files/EclipseConEU2012-m2e-talk.pdf ( " " ) .

0

All Articles