What are differences between “mvn clean package” and “mvn clean install” in maven?

Maven is entirely based on the build lifecycle. As you know that the build lifecycle has different phases. Each phase of the lifecycle represents a stage on the build.

Following are the phases of a default lifecycle:

validate – validate the project is correct and all necessary information is available
compile – compile the source code of the project
test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package – take the compiled code and package it in its distributable format, such as a JAR.
verify – run any checks on results of integration tests to ensure quality criteria are met
install – install the package into the local repository, for use as a dependency in other projects locally
deploy – done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

The differences:

mvn clean packagemvn clean install
This will clean the target folderThis will also clean the target folder
It will compile your codeIt will compile your code
This command will package your codeThis command will package your code
This will create jar if your pom says the project is a jarThis will create jar if your pom says the project is a jar
Once done it will put the jar in target directory by defaultOnce done it will put the jar in local repository
Reference:
Share