Skip to content
Latchkey

mvn package: Usage, Options & Common CI Errors

Build the distributable artifact - JAR or WAR - into target/.

package is the Maven lifecycle phase that takes compiled code and bundles it into a distributable format such as a JAR or WAR, placed in the target/ directory. It runs validate, compile, and test first.

What it does

package binds packaging plugins (maven-jar-plugin, maven-war-plugin, or maven-shade/spring-boot-maven-plugin) to produce the artifact whose type is set by <packaging> in the POM. Because it depends on the test phase, failing tests stop packaging unless tests are skipped.

Common usage

Terminal
mvn package
mvn package -DskipTests             # skip test execution (still compiles tests)
mvn package -Dmaven.test.skip=true # skip compiling AND running tests
mvn clean package                  # clean target first, then package

Common error in CI (and the fix)

Symptom: package fails with "Failed to execute goal ... on project: Could not resolve dependencies" or a test failure halting the build. Cause: either a missing dependency or a failing unit test in the bound test phase. Fix: resolve the dependency (mvn dependency:resolve) or fix the test; to produce an artifact for triage without running tests, use -DskipTests (do not use -Dmaven.test.skip in release builds, since untested artifacts can ship).

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →