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?
In a development environment, use the following call to build and install artifacts into the local repository.
mvn install
This command executes each default life cycle phase in order (validate, compile, package), before executing install.
First of all,
build
is not a phase in the standard Maven lifecycles, whereasinstall
is one.mvn install
will invoke all the phases up to the phaseinstall
, 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:
${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).-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 commandmvn 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, thetest
phase or theclean
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 more than one, it will ask you for the one to run:
In the above screenshots, you can see that there was 2 custom "Maven Build" run configuration, which were named
clean
andclean 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.