Maven Cheat Sheet

The Java build lifecycle — goals and phases, profiles, dependency diagnostics, and mvnw tricks.

Build & Package4 sections · 25 commands
⌘K

Lifecycle & Goals

7
mvn clean install

Clean, build, test, package, and install-ish

mvn compile

Compile sources only

mvn test

Run unit tests

mvn package -DskipTests

Package skipping tests

mvn verify

Run the full lifecycle incl. integration tests

mvn -DskipTests=false test

Force tests on

mvn help:describe -Dplugin=maven-compiler

Docs for a plugin

Dependencies

6
mvn dependency:tree

The dependency graph

mvn dependency:tree -Dincludes=org.slf4j

Filter the tree

mvn dependency:analyze

Used vs declared vs unused

mvn -version

Version, Java, and OS

mvn versions:display-dependency-updates

What's outdated

mvn dependency:purge-local-repository -DactTransitively=false

Force re-resolution

Profiles & Properties

6
mvn package -Pprod

Activate a profile

mvn install -DskipTests -Dspotbugs.skip=true

Skip checks by property

mvn -q ...

Quiet output

mvn -f path/pom.xml package

Build an alternate POM

mvn help:active-profiles

Which profiles are active

./mvnw clean verify

Use the Maven wrapper

Debugging Builds

6
mvn -e package

Stacktrace on failure

mvn -X package

Debug logging

mvn -pl module -am test

Build one module + its dependencies

mvn -o package

Offline mode

mvn -B clean install

Batch mode (no progress)

mvn site

Generate project reports