Repaso
EspaƱol

What is the difference between mvn package and mvn install?

Options

  1. There is no difference between them in Maven builds
  2. package makes the JAR; install also copies it to ~/.m2 (Correct option)
  3. install deletes the JAR from target/ after building
  4. package uploads the JAR to the internet repository

Answer

package builds the JAR in target/; install also copies it into your local Maven repository (~/.m2) so other local projects can depend on it

Why

Both compile, test and package. mvn package stops after creating the JAR/WAR in the target/ folder.

mvn install goes further and copies the artifact into the local repository (~/.m2/repository), so other projects on your machine can use it as a dependency.

mvn deploy goes even further and uploads to a shared remote repository (Nexus, Artifactory) for your team.

A common daily command is mvn clean install.

mvn clean install          # delete target/, build, test, install locally
mvn clean package -DskipTests   # build without running tests

Remember

package = JAR in target. install = + local repo. deploy = + remote repo.

Key terms

Practice this question in Repaso