Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "Maven Install" and "Maven Build" with M2Eclipse?

I tried to search about the differences between maven install and maven build in the eclipse m2e plugin (if you right click the project and click "run as", you will see them), and I still cannot find a good explanation of them (I looked through the official document as well). Anyone can help? From what I currently understand:

  • maven install: build and install the artifacts in to the local repository
  • maven build: only build but not install? what does install mean then?

Also, when you checkout a repository online, do you usually do maven install (to install everything, including the dependencies) in order to run the code?

like image 1000
RockTheStar Avatar asked Jun 23 '16 18:06

RockTheStar


People also ask

What is the difference between Maven clean and Maven install?

mvn clean install calls clean first, then install . You have to clean manually, because clean is not a standard target goal and not executed automatically on every install. clean removes the target folder - it deletes all class files, the java docs, the jars, reports and so on.

What is Maven install?

The Install Plugin is used during the install phase to add artifact(s) to the local repository. The Install Plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location for the artifact within the local repository.

What is meaning of Maven build?

Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. It simplifies the build process like ANT.


1 Answers

First of all, build is not a phase in the standard Maven lifecycles, whereas install is one. mvn install will invoke all the phases up to the phase install, which generally consists of compiling the source code, packaging the project and installing it in the local repository.

To be clear, we're talking about what M2Eclipse shows in the "Run As" selection.

enter image description here

What are all those options? First of all, you need to be aware that you can:

Configure custom "Run Configuration"s in Eclipse

By going to:

enter image description here

This will open a dialog where you can configure those custom configurations.

enter image description here

You can create a new "Maven Build" run configuration, by giving it:

  • a name: this will be the unique name of the configuration. You can name it as you like. Above, it is named with the goals that it will invoke.
  • the base directory: this will be the folder where Maven will be invoked in. In the above screenshot, I used the Eclipse variable ${project_loc}, which is replaced automatically by the base directory of the current selected project in the "Project Explorer" when run. (This allows to have a single run configuration for multiple projects).
  • goals, potential profiles and several options: all those options will make up for the exact command that will be launched. Adding a profile will launch Maven with a -P... attribute; checking "Update Snapshots" will launch Maven with the -U flag, etc.

So what are all those "Run As" options?

Maven install

This is the simple one: "Maven install" will launch the configured Maven installation in Eclipse with the goal install. It will have the same effect as running the command mvn install on the command-line, with an external Maven installation.

The options "Maven generate-sources", "Maven test" or "Maven clean" are actually following the same idea: all of those will directly invoke Maven with the generate-sources phase, the test phase or the clean phase.

Maven build...

This will actually launch the previous dialog where we created a new run configuration. What happens is that M2Eclipse will create a new one, that you can fill exactly like above. You could see it as a short-cut for creating custom "Maven Build" run configurations.

Maven build

This will try to launch the configured custom run configurations.

  • If you have only one custom "Maven Build" run configuration, it will launch that one.
  • If you have more than one, it will ask you for the one to run:

    enter image description here

    In the above screenshots, you can see that there was 2 custom "Maven Build" run configuration, which were named clean and clean install. As such, this pop-up is asking the user to select one.

Once the custom "Maven Build" configuration was chosen, it will then invoke Maven with the options in this run configuration.

like image 189
Tunaki Avatar answered Oct 20 '22 07:10

Tunaki