Skip to content
Latchkey

mvn package: Build the Artifact (Maven phase)

mvn package runs every default-lifecycle phase up to and including package: validate, compile, test, then package the compiled code into the configured artifact.

package is the phase that produces the jar/war. Because phases are cumulative, it also compiles and runs tests first unless you skip them.

What it does

Maven phases are cumulative: invoking package runs validate, compile, test, prepare-package, and package in order. The packaging plugin bound to your <packaging> (jar, war, etc.) produces the artifact in target/. Tests run during the bound test phase first.

Common usage

Terminal
mvn package
mvn package -DskipTests           # compile tests but do not run them
mvn package -Dmaven.test.skip=true   # skip compiling and running tests
mvn clean package

Flags

FlagWhat it does
-DskipTestsCompile tests but skip running them
-Dmaven.test.skip=trueSkip compiling and running tests
-pl <modules> / -amBuild selected modules and their dependencies
-oOffline mode
-BBatch (non-interactive) mode for CI

In CI

Run mvn -B package (batch mode) and cache ~/.m2/repository so dependencies are not re-downloaded every job. Use -DskipTests only when a separate stage runs the tests; otherwise let package run them so a broken build does not get packaged.

Common errors in CI

"Failed to execute goal ... maven-compiler-plugin ... Compilation failure" is a source error before packaging. "There are test failures" from the surefire plugin stops package; the report is in target/surefire-reports. "Failed to execute goal ... could not resolve dependencies" is a network/cache miss, fixed by warming ~/.m2.

Related guides

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