Difference between “mvn clean package” and “mvn clean install” ?

mvn clean package : Package command does below thing

  1. Validate :- Validate the project is correct and all necessary information is available or not .
  2. Compile :- Compile your source code of the project.
  3. Test(optional) :- Test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
  4. Package :- Take the compiled code and package it as a jar or war as per pom file and move into target folder.

So when you run the command mvn package, it runs the commands for all lifecycle phases till package.

mvn clean install: Install command does below thing:

  1. Validate :- Validate the project is correct and all necessary information is available or not .
  2. Compile :- Compile your source code of the project.
  3. Test(optional) :- Test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
  4. Package :- Take the compiled code and package it as a jar or war as per pom file and move into  target folder.
  5. verify – Run any checks on results of integration tests to ensure quality criteria are met.
  6. install – Install the package into the local repository, for use as a dependency in other projects locally.
  7. deploy – Done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

So when you run command mvn install, it runs the commands for all lifecycle phases till install, which includes package as well. So you can say , install phase comes after package phase.

  • mvn package command will compile source code and also package it as a jar or war as per pom file and put it  into the target folder(by default).
  • mvn install command will compile and package, but it will also put the package in your local repository. So that other projects can refer to it and grab it from your local repository.

3 thoughts on “Difference between “mvn clean package” and “mvn clean install” ?

Leave a comment