Eclipse Photon does not resolve imports in test sources
Eclipse Photon does not resolve imports in test sources
I have moved to Eclipse Photon with an existing workspace. I have some Maven projects in this workspace. All projects did not have any errors in Eclipse Oxygen. After opening my workspace in Eclipse Photon all test-classes which import org.mockito.Mockito
, org.springframework.mock
and org.springframework.test
have errors. These imports cannot be resolved though Eclipse is aware of them as I can jump into the classes.
org.mockito.Mockito
org.springframework.mock
org.springframework.test
Why can Eclipse Photon not resolve these imports? And how can I fix this?
2 Answers
2
If this is really a maven project and you are using matching m2e-version 1.9, it should automatically configure the "Contains test sources."-setting and the related settings correctly.
You may have to update the project classpath by right-clicking on the project and Choosing "Maven" > "Update Project"
I solved it and want to share my results.
The build path properties in eclipse photon have a new option in the source tab: Contains test sources. This option was set to No for the folder myproject/src/test/java
. When I tired to set it to Yes I got the error:
myproject/src/test/java
The source folder 'src/testjava' in project 'myproject' must have an
output folder that is not also used for main sources
The error was shown although the output folder was already set to a different path than that of myproject/src/main/java
. To reset the settings I unchecked the option Allow outoput folders for source folders and set all output folders again. After that I was able to set the mentioned option to Yes. As the result of it the imports got resolved.
myproject/src/main/java
The reason is described here (scroll down there to Test sources). It says:
For each project, compilation is now done in two phases: First all
main sources (which cannot see any test-code on the build-path) and
then all test sources.
Since the option wasn't set for the test-source-folder it was compiled like a main-source-folder. Therefore the imports of test classes from deependencies with scope test could not be resolved.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I've did an Maven "Update Project" on an other project having the same issue. It solved it. I think this is the appropriate answer regarding how to solve it..
– LuCio
Jun 29 at 13:15