Tuesday, July 5, 2022

Difference between "Maven Install" and "Maven Build"

 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.


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:



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




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.