Reputation: 9966
I'm using Eclipse 4.3.1 with Maven Integration.
Eclipse doesn't recognize the difference between normal source files and test source files.
For example: When I use a class of Mockito which's scope is test in the normal source folder, everything seems fine. Or when I erroneously create a class in the test source folder, nothing happens.
Only when Jenkins does the Maven build, the compile errors are shown.
Can I somehow make Eclipse work properly?
Upvotes: 1
Views: 181
Reputation: 7994
You have to make a difference between run time and compile time.
Compile time: Eclipse only supports one build path per project. If your test files and your application files share the same project they share the same compile time classpath. This means you can access any classes in your src directory (test or main) and classes from any dependency. Eclipse can't mark this as error because it doesn't see a difference between all these files.
Run time: Eclipse allows different classpaths at runtime and m2e supports this. Every forbidden access results in a RuntimeException (ClassNotFoundException).
Access at runtime is as follows:
# access from -> access to
src/main/java -> jar(scope: compile) [allowed]
src/main/java -> jar(scope: test) [forbidden]
src/main/java -> src/test/java [forbidden]
src/test/java -> jar(scope: compile) [allowed]
src/test/java -> jar(scope: test) [allowed]
src/test/java -> src/main/java [allowed]
To answer your question: What you want is not possible without patching eclipse. Although you could split your test files and your application into separate projects.
The simplest solution is to run/test your application on your local machine before checking in.
Upvotes: 2