mvn clean install vs. deploy vs. release
Solution 1
The clean
, install
and deploy
phases are valid lifecycle phases and invoking them will trigger all the phases preceding them, and the goals bound to these phases.
mvn clean install
This command invokes the clean
phase and then the install
phase sequentially:
-
clean
: removes files generated at build-time in a project's directory (target
by default) -
install
: installs the package into the local repository, for use as a dependency in other projects locally.
mvn deploy
This command invokes the deploy
phase:
-
deploy
: copies the final package to the remote repository for sharing with other developers and projects.
mvn release
This is not a valid phase nor a goal so this won't do anything. But if refers to the Maven Release Plugin that is used to automate release management. Releasing a project is done in two steps: prepare
and perform
. As documented:
Preparing a release goes through the following release phases:
- Check that there are no uncommitted changes in the sources
- Check that there are no SNAPSHOT dependencies
- Change the version in the POMs from x-SNAPSHOT to a new version (you will be prompted for the versions to use)
- Transform the SCM information in the POM to include the final destination of the tag
- Run the project tests against the modified POMs to confirm everything is in working order
- Commit the modified POMs
- Tag the code in the SCM with a version name (this will be prompted for)
- Bump the version in the POMs to a new value y-SNAPSHOT (these values will also be prompted for)
- Commit the modified POMs
And then:
Performing a release runs the following release phases:
- Checkout from an SCM URL with optional tag
- Run the predefined Maven goals to release the project (by default, deploy site-deploy)
See also
Solution 2
-
mvn install
will put your packaged maven project into the local repository, for local application using your project as a dependency. -
mvn release
will basically put your current code in a tag on your SCM, change your version in your projects. -
mvn deploy
will put your packaged maven project into a remote repository for sharing with other developers.
Resources :
Related videos on Youtube

Comments
-
Mahdi Yusuf about 2 years
I am just learning maven, and we have recently needed to go more and more. I would like to know the difference between
mvn clean install
mvn release
mvn deploy
Please be as descriptive as possible.
-
gvlasov over 7 yearsCan you please clarify this: This is not a valid phase nor a goal so this won't do anything. But if refers to the Maven Release Plugin. If it is neither a phase nor a goal, then how do we call it?
-
PANDA MAN almost 2 yearswhat are the implication if i put clean on every command? lets say, mvn clean install and then perform another command mvn clean deploy? will it work the same?
-
Jawad 7 monthsinstall runs after deploy and they are both lifecycle phases. These are dependent on each other and execute serially one after another in order (build then test then package then install then deploy). Every phase invokes all of its dependent phases in order (as defined by maven, see lifecycle phases docs). So in short... deploy will run everything that install run, so you are wasting time by doing mvn install, just do mvn deploy.