Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does Maven Update Project do in Eclipse?

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:

  1. Does Update project run any Maven plugin and, if so, which ones and with which default settings?
  2. Are there effects which are not a result of a Maven plugin, but are internal to Eclipse?
  3. What are the modifications on the project structure? For instance, are Maven dependencies copied locally?
like image 817
burubum Avatar asked Mar 02 '17 11:03

burubum


People also ask

How do I run a Maven update project?

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

What is Maven project in Eclipse?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

What is Maven force update?

Force Update All SNAPSHOT Dependencies. As we know already, Maven will not download existing dependencies again. Therefore, to force Maven to update all corrupted SNAPSHOT dependencies, we should add in our command the -U/–update-snapshots option: mvn package -U mvn install -U.


1 Answers

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.
like image 108
GauravJ Avatar answered Oct 17 '22 20:10

GauravJ