What Does Maven Update Project Do in Eclipse

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.

What exactly does Maven Update Project do in Eclipse?

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)

  1. Project is refreshed with respect to file system. This is similar to calling refresh on the java project in eclipse.
  2. 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.
  3. Build maven project model using maven-core libraries.
  4. Lifecycle mapping refresh - M2Eclipse tries to map some of the plugin lifecycles to eclipse actions. For more information, check
  5. 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

  1. Adding Maven nature (org.eclipse.m2e.core.maven2Nature in .project file) - not important in your context. See this.
  2. Setting default charset for your project based on project.build.sourceEncoding maven property.
  3. Eclipse - plugin lifecycle processing. Point 3 above.

what is the difference between refresh and update project in eclipse

A quick google search yielded this result: What does Maven Update Project do in Eclipse?

The correct answer states:

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.

So in short,

  • Updating your project through maven synchronizes the settings with that of pom and keeps all the settings synchronized between the pom and the project.

  • Refreshing your project through eclipse will reload the project - that is reload all the files and apply any external changes from the files to the project.

Note that a maven update will cause a refresh of the project in eclipse.

How to update maven repository in Eclipse?

You can right-click on your project then Maven > Update Project..., then select Force Update of Snapshots/Releases checkbox then click OK.

What is the difference between maven update and maven build?

When you run maven update - your local maven repository gets updated with the latest jars from central repository. This is important for SNAPSHOT versions of artifacts. SNAPSHOT version of artifacts in the local repository maybe out of date with what's currently available in your central repository.
*build happens in eclipse because the build automatically option is selected. if it's not it won't happen.

When build - complies, runs test and builds you current projects artifacts. maven build usually includes a maven update phase unless run with the offline option (-o).

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).

So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.

As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:

Sample Image

If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.

Sample Image



Related Topics



Leave a reply



Submit