What does "Maven -> Update Project..." do in Eclipse?
It syncs the Eclipse project settings with that of the pom. If you for example change important plugin settings, such as the output java version, you will find that Eclipse will ask you to update the project and afterwards the configured Java runtime in the project will have changed to reflect what your Maven pom indicates.
That is an important thing to keep in mind: the Maven pom is the lead in this kind of project setup. If you want settings to change, try to do that through the pom and not through Eclipse project settings directly or doing a project update might revert what you have changed. There are usually some things I have to correct myself anyway though, such as build path exclusions that m2eclipse likes to put in and strange deployment assembly configurations.
To add on to what #Gimby said - Update Project also provides more options such as Force Update of Snapshots / Releases which is extremely helpful when you have dependencies that are looking for the latest. (e.g.: [1.0) will find 1.0.* - whatever's the latest.)
Updating project is synonymous with Ivy's Resolve. It will make sure that all referenced dependencies are there, as well as clean the project to make sure that they are included correctly.
I could not dig out the documentaiton, but I was able to dig out the code. To complement #Gimby answer - you can go into details and look into what the function does in here:
https://github.com/eclipse/m2e-core/blob/41f5ae34ad2543ef1439b7fd7e0a03b596af8685/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java#L365
Look for : updateProjectConfiguration0 function.
Cheers,
Related
First of all, I am aware of this question, but I am interested in the details which are not provided there.
I had a look at the documentation of m2eclipse and found it unsatisfactorily laconic. The only relevant part I could find is
Alternatively you can run “Maven / Update project configuration” action from the project popup menu, which is configured to run “process-resources” by default and it can be also changed on the same preference page.
but I could not make whether Update project configuration is the same as Update project. All other sources I have found while browsing around do not provide any details either.
To recap, what I would like to know is:
Does Update project run any Maven plugin and, if so, which ones and with which default settings?
Are there effects which are not a result of a Maven plugin, but are internal to Eclipse?
What are the modifications on the project structure? For instance, are Maven dependencies copied locally?
Does Update project run any Maven plugin and, if so, which ones and with which default settings?
During the update project, m2eclipse uses maven-core build project object model. Specifically, maven model builder is used to build project model. In other words, it leads to dependency resolution, error and warning notification. For more information about the result, you can check org.apache.maven.project.ProjectBuildingResult
I don't think that it results in running of plugins. I took a cursory look and phase 2 while doing update is not enabled which does plugin processing.
Are there effects which are not a result of a Maven plugin, but are internal to Eclipse?
Yes. See the end section of the answer.
What are the modifications on the project structure? For instance, are Maven dependencies copied locally?
If by locally you mean, in eclipse workspace then no. Maven Dependencies shows reference to the local repository which is usually /.m2/repository. The Repository is also resolved based on the setting of Eclipse menu "Windows->Preference->User Settings".
For further information, you can begin from the following source code (one of the methods invoked when you do update project in eclipse),
public IStatus runInWorkspace(IProgressMonitor monitor) {
...... Unimportant stuff
MavenUpdateRequest request = new MavenUpdateRequest(projects, offline,forceUpdateDependencies);
Map<String, IStatus> updateStatus = configurationManager.updateProjectConfiguration(request, updateConfiguration,
cleanProjects, refreshFromLocal, monitor);
...... Unimportant stuff
}
Summary of different tasks performed (not exhaustive)
Project is refreshed with respect to file system. This is similar to calling refresh on the java project in eclipse.
Check if one of the dependencies have been added in the workspace. You must have noticed under maven dependencies local project folder. Junit and other stuff will pick changes using this feature.
Build maven project model using maven-core libraries.
Lifecycle mapping refresh - M2Eclipse tries to map some of the plugin lifecycles to eclipse actions. For more information, check
Finally, Builds Project using Eclipse build mechanism
Additionally, it also does some stuff with parent pom presence in the workspace which is not very important in this context.
Update Project configuration is majorly related to
Adding Maven nature (org.eclipse.m2e.core.maven2Nature in .project file) - not important in your context. See this.
Setting default charset for your project based on project.build.sourceEncoding maven property.
Eclipse - plugin lifecycle processing. Point 3 above.
I imported my existing maven projects under eclipse.Once imported i found under Java Build Path > Source resource foulder is
excluded(i can see Excluded:**) from build and does not get copied under target > classes directory.
I can remove exclusion manually by selecting Excluded:** and then click Remove, But there are large numbers of projects. Is there
a setting in eclipse where i can do it one go ?
That's part of what Maven does when you let it generate your Eclipse project settings (via the eclipse:eclipse plugin/goal). It's quite misleading. However, if you have the m2e plugins installed into Eclipse it coordinates things correctly.
What's going on, as best as I can figure: Eclipse's built-in Java builder automatically copies non-Java files found on the build path to the output location (unless they're excluded as you see in your Build Path). Problem is, when Maven comes in the picture it, too, wants to copy resources during a build. So to keep the two builders from competing/interfering with each other, Maven instructs Eclipse to ignore resources so it (Maven) can manage copying them during a build.
m2e integrates into the Eclipse build process to do the Maven copying of those files, so if you configure the project as an m2e project things will "just work," both in Eclipse and if you build from a command line.
I don't know of a way to tell Maven to not configure the project this way. To be honest, that's just one of the reasons I prefer to not let Maven generate my Eclipse project files; I do a much better job of it and I totally control the specifics rather than relying on whatever the Maven eclipse developers think is best.
This is an old question, but I've been looking for the answer and I finally dug it up myself. According to the M2Eclipse FAQ the import intentionally excludes resources. This is because Maven performs special resource handling that includes filtering.
Let Maven do the building for you. Disable automatic building in Eclipse and never build your projects in Eclipse.
I have a Maven project that needs to be versioned. I have chosen to use the versions-maven-plugin as my versioning plugin but am unsure if that's the best option.
I have read the documentation that such plugin actually modifies the POM and I don't really like that approach. I have worked on projects where they had separate build.properties file that got modified manually.
What I want to achieve is to have my CI generating the artifact for me ready to be deployed and update the version number automatically.
So, any suggestions? How have you done before?
Thank you
I'd get the version number from the one source that matters: that's the source code management system (Subverson, Mercurial, or Git), not Maven.
I'd say that Maven might be out of synch unless your Maven plug-in is getting it from SCM.
Use the Release Plugin. You want to perform automatic deployment and batch release. The Versions Plugin is designed for something else.
We have found MAVEN-RELEASE-PLUGIN super useful and can not imagine releasing and managing version with it.
We as a development team were always happy with subversion and eclipse, we checked in everything and everything was fine. Until we had a new hire who's using anything but eclipse (RAD ). his RAD checkins are currently polluting the svn repo withholding our eclipse checkouts to finish building.
One solution may be to force eclipse in the new hirer's throat, another more subtle and probably more suitable approach is to make our project ide agnostic.
Instead of removing the files by trial and error I hope to learn a quick and reliable solution.
I already learned that i should
remove files and add them to the svn
global ignore. I'm wondering is there
a way to make this project wide
instead of having everybody fixing
their own svn config? Something to add to your root .svn directory?
I'm also
looking for a list or even script to
remove the eclipse files and
directories from the svn repo
(.project .settings .classpath??
.externalToolBuilders .springBeans)
without running the risk of
completely ruining the workspace.
I'm
also intested in finding the quickest
way of restoring the workspace, as
we're using maven for software
project management I can do mvn
eclipse:eclipse in the root of
workspace but how do I find what the
proper WST settings are, and what is the quickest way or restoring your path settings in eclipse ?
I thought that many people would have been faced with the same use case, and consequently had the same questions but I haven't found anything on Google yet. Hopefully somebody here can point me in the right direction.
If you want to have a language-agnostic code repository the question is less about which files to exclude that about which files to include. Meaning, in a language-agnostic repo there should really only be the files necessary for the project:
source files, libraries, property files, .xml config, ...
built stuff, i.e. .class files, archives, ...
You should certainly exclude:
.project - this is project specific config by eclipse
.settings folder - this is project specific config by eclipse
.classpath - also eclipse specific
In Eclipse there is a 'global' ignore list for files which are shared to repositories via SVN, CVS, etc. You can find it here:
Window > Preferences > Team > Ignored Resources
If you're looking for something outside Eclipse, try the global-ignores config in your local subversion config. Add this to your ~/.subversion/config file.
global-ignores = build *.mode* *.pbxuser *~.nib .DS_Store *~
Mind that if excluding the Eclipse config from the repos you'll have to set up your projects after a checkout more specifically.
However, as you say you're using Maven this should not pose too many problems for you actually. If the pom.xml files of maven projects are configured correctly and completely, you can easily import a project from SVN via 'Import as Maven Project' - Eclipse will do all the right config for you on the import. (For this you need the m2Eclipse Maven Plugin, but I guess you'll be using something like that already? Anyway, here's the link: http://m2eclipse.sonatype.org/sites/m2e )
As for your question concerning a script to clean the repo: I'm not aware of such a thing right now, and I'd be very careful with this. Sounds like a lotta things could go horribly wrong. ;)
Last but not least, restoring the workspace:
In my experience, it is often the easiest thing to just delete your project locally and to a fresh checkout 'as maven project'. This way Eclipse will reconfigure all the important stuff. I have spent hours on broken Eclipse config, sometimes it tends to just get stuck and fails to be able to recover - especially if you're working with a lot of plugins which tend to do some of their own configuration magic. (And happen to be not exactly bug free...)
So every time I add a dependency to a library using maven in my pom.xml, it doesn't get deployed until I go to module settings and then click on 'fix'.
This happened when I added freemarker.
Why doesn't IDEA do this for me? Am I missing a step?
Not sure about previous versions but with IntelliJ 9, IntelliJ shows me a Import Changes link when I modify a pom.xml and also offers to Enable Auto-Import:
alt text http://www.imagebanana.com/img/emcut3ku/screenshot_008.png
The auto-import option is also available from the Maven Integration dialog: File > Settings > Maven > Importing > Import Maven projects automatically.
IDEA stores all of your module's dependencies in either a .iml or .classpath file (based on your preference).
When you change the pom.xml file, it needs to resolve the new set of dependencies (Re-import) and update the file accordingly. I can only imagine that they don't do this automatically for you because they can never really know when you are done working with the file, and causing resolution of dependencies to start while you're still typing would make working with pom.xml from within idea very irritating.
AFAIK, you're doing it right. In my version of IDEA, I see a "re-import" button that appears in the pom file editor (which saves a couple of clicks)... or you can go to the "Maven Projects" window and click the "Re-Import Maven Projects" button, but these should do the same thing as your "Fix" button in the project settings.
The original question referred to a library that wasn't deployed -
IntelliJ uses artifacts to deploy build output and required libraries to application/web servers, and currently those can include a constant list of dependencies. Clicking the "fix" simply adds module dependencies to the artifact, if they weren't already there.
Since in most use-cases this is 1:1, i.e. artifacts contain all module dependencies, I have opened an feature issue for it:
http://youtrack.jetbrains.com/issue/IDEA-99458