简体   繁体   中英

Maven clean + build causes project in Eclipse to show errors until clean in Eclipse

We are getting a very weird behavior in our development environment that is consistent with all of our developers on different operating systems.

We have about 20+ Maven (3.0.4) projects in the development environment, all of them are open projects in Eclipse (Indigo) with sonatype m2e (0.12.0) handling dependencies as usual. (m2e 1.0 is causing us more problems than solutions)

Out of all our 20+ projects there is one project that's acting weird. When performing mvn clean install on that project, even though Maven passes successfully , it causes 4 java files (in the unit tests, if it makes any difference) to show errors in Eclipse.

The errors are of the type "SomeNameOfClass cannot be resolved to a type" although opening the file and pressing F3 (Open declaration) on the erroneous class reference finds the class without a problem.

mvn clean is the problem, if we just run mvn install this doesn't happen.

Eclipse's Project -> Clean clears the errors and everything is ok.

This is not an operational problem that actually prevents me from working or anything like that, I can solve it simply by cleaning in Eclipse, I just hate doing that every time and I can't stand red Xs in my projects even if they have no effect.

I'm just really really curious why this is happening at all, why specifically those 4 classes? why why why? :)

We have had the exact same problem a while ago. We had more than 20 projects giving the same kind of error. From the investigation we did, we concluded that when maven clean install is run, eclipse loses track of the class files and thinks some of them are undefined. The solution we had is to issue the following at the command line:

mvn eclipse:clean
mvn clean install
mvn eclipse:eclipse

This is now possible to specify that project(s) needs a refresh upon completion under Refresh tab in Run configuration . You will have to check Refresh resources upon completion and select which behavior below.

我发现在 maven 中有一个 jar 作为“测试”范围会导致“未解析的类型”错误,我发现的任何东西都不会修复它,除了将它从 pom 文件中的测试范围中取出。

If you want to get rid of errors through UI, do the following steps:

Select your project in eclipse and do ALT + ENTER OR right click on project -> Build path -> Configure Build Path

Select Java Build Path option and Source tab.

Select node(s) for which it shows error eg src/main/java and click Remove and Click Apply .

Again add the same(removed) node(s) using Add Folder option and click Apply and Close button.

Error(s) should have disappeared!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM