Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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? :)

like image 839
Enrico Avatar asked Mar 14 '12 08:03

Enrico


People also ask

What happens when we clean project in Eclipse?

It removes whatever already-compiled files are in your project so that you can do a complete fresh rebuild.

What happens when we do Maven clean?

Maven clean goal (clean:clean) is bound to the clean phase in the clean lifecycle. Its clean:cleangoal deletes the output of a build by deleting the build directory. Thus, when mvn clean command executes, Maven deletes the build directory.


1 Answers

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 
like image 171
GETah Avatar answered Oct 01 '22 07:10

GETah