This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I have maven project module, which on first build works fine. But after I call 'mvn clean' and then 'mvn install', project crash on java errors (inconvertible types, etc...).
The only solution I found was in Eclipse: right click on project module -> Maven -> Update Project Configuration. After this step 'mvn install' again works fine. But only until the time, when I again call mvn clean on project.
It is multi module project and only this one module produces this problem. So the question is: does 'mvn clean' erase some of my dependencies or something what is needed?
mvn clean primarily erases the "target" directory and everything under it, since that's where both intermediate and final files are produced. Version control systems should place that directory on their "ignore" lists, since A) everything in target should be re-creatable and B) the "clean" operation nukes all of the version control metadata for target and its children anyway.
A properly laid-out maven project will never place "permanent" files under the target directory, and Maven shouldn't be cleaning out anything else.
One thing you should pay attention to, however, is where Eclipse is building classfiles generated by its internal compiler. Eclipse favors "PROJECT_ROOT/bin" and Maven doesn't work that way. So check your project preferences.
Customer surveys are for companies who didn't pay proper attention to begin with.
Could you please provide a complete stack trace of the error?
Joined: Apr 21, 2011
eclipse output folder is set to "PROJECT_ROOT/target/classes", so this is correct i think...
running maven commands do same either they are called from command line or from eclipse
I can't past complete stack trace of error, because it is commercial project, but IMHO I don't think the type of error is important. I provide you with sample code:
This code works fine at beginning. I can build it without problems. Then I call maven clean, either from terminal of from eclipse. When I try to build project after that clean, maven prints error about inconvertible types, something like this:
[ERROR] /home/pathtomyproject/project-name/src/main/java/package/MyProject.java:[140,47] inconvertible types
[ERROR] found : package.MyParent<capture#994 of ?>
[ERROR] required: package.MyChild1
[ERROR] /home/pathtomyproject/project-name/src/main/java/package/MyProject.java:[147,8] inconvertible types
[ERROR] found : package.MyParent<capture#994 of ?>
[ERROR] required: package.MyChild2
This could be fixed as I mentioned in my first post easily with eclipse: right click on project -> Maven -> Update Project Configuration. But why I have to update project configuration every time after calling clean? I don't understand...
If I'm interpreting that correctly, you have a conflict in the use of a templating class. The most likely cause is that there's more than one version of the class being pulled in.
Check your project to see if there are multiple jars in it that include that class. Often, although not always, you will find that two different jar versions are being used and this will become apparent if you use the Eclipse maven dependency hierarchy view to display what jars are being pulled in and how they interrelate.
You can also do this from the command line, but the Eclipse GUI tool is easier to use.
Are all of these class in the same project, or are some of them in a separate project? If a separate project, are you using a SNAPSHOT version? If so, then each time you build that other project you will get a different JAR file (snapshots include a timestamp in the jar file name), and m2e has to update Eclipse to reference the correct JAR file for your project. (This is all a guess...)
There is definitely only 1 version of parent nad child class.
Peter Johnson wrote:Are all of these class in the same project, or are some of them in a separate project? If a separate project, are you using a SNAPSHOT version? If so, then each time you build that other project you will get a different JAR file (snapshots include a timestamp in the jar file name), and m2e has to update Eclipse to reference the correct JAR file for your project. (This is all a guess...)
These classes are in different modules, but under one project. Each module is versioned as 1.0, so they are not SNAPSHOTs. But your point seems to me very likely as possible problem.
By the way, I found another way which relatively solve this problem - removing generics:
But changing code with removing generics I don't consider as a good solution...
However, we redefined generics in parent class and also in child classes and now code works. But I don't certainly found out why this problem occured in former code and is still weird for me.
Maven does some strange things when you build multi-module projects. That's why I keep on trying to convince the developers I work with to do individual projects and let Jenkins run the builds one after the other. But so far I haven't had much success...
By the way, are you using Maven 3.0.4? If not, try it, there were a number of multi-project related issues that got fixed in that release.