All cheatsheetsJava Development

maven

Maven 3.9+

Quick reference for Maven CLI commands: project lifecycle phases, dependency management, plugins, multi-module reactors, repository deployment, and debugging — with common options and practical examples.

34 commands

Lifecycle phases

mvn validate

Validate the project structure: download metadata, parse `pom.xml`, sanity-check dependencies.

-N only the root reactor (no submodules); -f <pom> use alternate POM; -P<profile> enable profile

mvn validate
mvn compile

Compile the project's main `src/main/java` into `target/classes`. Uses the configured JDK and `maven-compiler-plugin`.

-DskipTests; -T 4 parallel build threads; -q quiet

mvn compile
mvn test

Run unit tests (Surefire) against compiled main + test sources. Skips `failsafe` (integration tests) — use `mvn verify` for that.

-Dtest=ClassName; -Dtest=Class#method; -DfailIfNoTests=false; -Dsurefire.useFile=false

mvn test -Dtest=UserServiceTest
mvn package

Run every prior phase, then package the compiled output into a JAR / WAR / EAR under `target/`.

-DskipTests; -Dpackaging=jar

mvn package -DskipTests
mvn verify

Run package plus integration tests (Failsafe), then verify everything is shippable. Does **not** install or deploy.

-DskipITs; -DskipTests

mvn verify -DskipITs
mvn install

Run verify, then copy the produced artifact into the local Maven repository (`~/.m2/repository`) so other local projects can depend on it.

mvn install -DskipTests
mvn deploy

Build and push the artifact to the remote repository declared in `pom.xml`'s `<distributionManagement>` (Nexus / Artifactory / Maven Central via Sonatype).

-DskipTests; -P release use release profile

mvn deploy -P release -DskipTests
mvn clean

Delete the `target/` directory to start from a fresh state.

mvn clean
mvn clean install

Wipe `target/` then run through `install`. The most common "rebuild from scratch" command.

-U force-update of snapshot dependencies

mvn clean install -U

Dependencies

mvn dependency:tree

Print the resolved dependency tree (with conflict resolution) — invaluable for chasing `NoSuchMethodError` from version skew.

-Dincludes=<groupId>[:<artifactId>[:<version>]]; -Dverbose

mvn dependency:tree -Dincludes=com.fasterxml.jackson.core
mvn dependency:resolve

Resolve every dependency into the local repo without executing the lifecycle.

mvn dependency:resolve
mvn dependency:analyze

Compare declared `<dependencies>` against actual `import` / `package` usage; flags unused / undeclared deps.

mvn dependency:analyze
mvn dependency:list

List every resolved dependency in the build as plain `groupId:artifactId:type:version` lines.

mvn dependency:list | grep slf4j
mvn versions:display-dependency-updates

List every dependency that has a newer version available in the configured repositories.

mvn versions:display-dependency-updates

Multi-module

mvn -pl <module> <goal>

Run a goal against one or more specific submodules by artifact ID (comma-separated).

-am also build the modules the target depends on

mvn -pl user-service,order-service -am test
mvn -pl <module> -am <goal>

Build the named module plus every module it depends on. `-amd` (also-make-dependents) is the inverse.

mvn -pl web -am package
mvn -T 4 <phase> / mvn -T 1C <phase>

Parallel reactor: `-T 4` uses 4 threads; `-T 1C` uses 1 thread per CPU core. Speeds up multi-module builds.

mvn -T 1C clean install

Repository

mvn help:effective-pom

Print the final merged POM (super-POM + parent POM + active profiles + current settings) to a single file — the source of truth at build time.

-Doutput=<file>

mvn help:effective-pom > effective.xml
mvn help:effective-settings

Print merged `~/.m2/settings.xml` + global + CLI-`--settings`. Useful for chasing mirror / credential resolution.

mvn help:effective-settings -s ./settings.xml
mvn -s <settings.xml> <phase>

Override the user `settings.xml` for one build — handy for CI with mirrored repos.

mvn -s ./.mvn/settings.xml deploy

Plugins

mvn <plugin>:<goal>

Run a single plugin goal directly. Common: `compiler:compile`, `surefire:test`, `jar:jar`, `deploy:deploy`, `dependency:tree`.

-D<param>=<value> goal parameter; -X debug (very verbose)

mvn compiler:compile && mvn surefire:test -Dtest=*ServiceTest
mvn help:describe -Dplugin=<id>

Show every goal and parameter of a plugin. Substitute `<id>` with the `groupId:artifactId`.

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin

Profiles

mvn -P<profile1>,<profile2> <phase>

Activate one or more profiles declared under `<profiles>` in `pom.xml` or `settings.xml`.

mvn -Pprod,fast test
mvn -P!<profile> <phase>

Deactivate a profile that would otherwise be active by default.

mvn -P!javadoc package

Debugging

mvn -X <phase>

Enable debug logging — prints every plugin execution, repository lookup, and download URL. Pipe to file.

-e full stack traces on errors

mvn -X test > mvn-debug.log 2>&1
mvn -e <phase>

Print full stack traces on any failure. Combine with `-X` for maximum detail.

mvn -e -X deploy
mvnDebug <phase>

Start the build with the JVM suspended on a JDWP socket (default port 8000) so you can attach a debugger at line 1 of the Maven JVM.

mvnDebug test

Wrapper

./mvnw <phase>

Run a build through the Maven Wrapper — uses the Maven version pinned in `.mvn/wrapper/maven-wrapper.properties`. Always check in the wrapper.

-Dmaven.version=<ver> upgrade Maven for this run

./mvnw clean install
mvn wrapper:wrapper

Generate / refresh the Maven Wrapper files (`mvnw`, `mvnw.cmd`, `.mvn/wrapper/*`).

-Dmaven=<version> pin the Maven distribution version

mvn wrapper:wrapper -Dmaven=3.9.6

Misc

mvn --version

Print Maven version, JDK, OS, and locale.

mvn --version
mvn --help

List every CLI flag and supported property.

mvn --help | head -40
mvn -B <phase>

Batch / non-interactive mode — disables interactive prompts and color output. Use in CI to avoid hanging on a missing property.

mvn -B -ntp clean verify
mvn -ntp <phase>

Disable the new transfer-progress bar (recommended in CI; reduces log noise and avoids CPU spikes on slow mirrors).

mvn -B -ntp clean deploy
mvn -o <phase>

Offline mode — never call out to remote repositories. Fails fast if a required artifact isn't in the local repo.

mvn -o test

Related command cheatsheets

About Maven

Apache Maven is a Java project management and comprehension tool that debuted in 2002 (originally created by Jason van Zyl). It models a project with a declarative `pom.xml` (Project Object Model) and executes a well-defined build lifecycle with eight default phases: `validate`, `compile`, `test`, `package`, `verify`, `install`, `deploy`. Maven was the first mainstream Java build tool to enforce a single repository layout (`groupId:artifactId:version`) and dependency resolution from a remote repository (Maven Central). The current stable line is Maven 3.9+. Maven downloads artifacts into the local repository (`~/.m2/repository` by default) and resolves transitively, with optional scopes (`compile`, `provided`, `runtime`, `test`, `system`, `import`). Plugins extend the lifecycle; common ones include `maven-compiler-plugin`, `maven-surefire-plugin`, `maven-jar-plugin`, and `maven-deploy-plugin`. Profiles (`-P`) override defaults per environment. Maven never uploads source code — `deploy` only ships the artifacts (jar/war/pom) configured in `distributionManagement`. Wrapper scripts (`mvnw` / `mvnw.cmd`) ship a Maven version per-project to lock the toolchain.

Cheatsheet version 1.0.0