Fortress Maven Learning Portal

Maven Cheat Sheet — Commands, Lifecycle & Essential Plugins

Getting Started with Maven

Fortress Java Learning Portal — Maven Cheat Sheet

This conversion follows the uploaded one-page Maven cheat sheet and preserves its main sections: project creation, command-line options, Maven lifecycle phases, and essential plugins. fileciteturn2file0L2-L6

1. Getting Started with Maven

Create Java Project

mvn archetype:generate
-DgroupId=org.yourcompany.project
-DartifactId=application

Create Web Project

mvn archetype:generate
-DgroupId=org.yourcompany.project
-DartifactId=application
-DarchetypeArtifactId=maven-archetype-webapp

Create Archetype from Existing Project

mvn archetype:create-from-project

Main Phases

clean — delete target directory
validate — validate, if the project is correct
compile — compile source code; classes stored in target/classes
test — run tests
package — package compiled code as JAR/WAR
verify — verify the package is valid and meets quality criteria
install — install the package into the local repository
deploy — copy the final package to the remote repository

2. Useful Command Line Options

Skip Tests

-DskipTests=true  — compiles tests, but skips running them

Skip Test Compilation

-Dmaven.test.skip=true  — skips compiling and running tests

Parallel Builds

-T 4  — 4 threads; a decent default
-T 2C — 2 threads per CPU

Resume / Select Modules

-rf, --resume-from — resume build from specified project
-pl, --projects — build only specified modules
-am, --also-make — build required dependent modules too

Other Useful Options

-o, --offline — work offline
-X, --debug — enable debug output
-P, --activate-profiles — comma-delimited profiles to activate
-U, --update-snapshots — check for updated remote dependencies
-ff, --fail-fast — stop at first failure

3. Essential Plugins

Help Plugin

mvn help:describe — describes plugin attributes
mvn help:effective-pom — displays the effective POM with active profiles factored in

Dependency Plugin

mvn dependency:analyze — analyzes project dependencies
mvn dependency:tree — prints the dependency tree

Compiler Plugin

Compiles Java code and can set the language level.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.1</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
  </configuration>
</plugin>

Version Plugin

Used to manage artifact versions in a project's POM.

Wrapper Plugin

Helps ensure Maven users have everything required for the build.

Spring Boot Plugin

Compiles a Spring Boot application and builds an executable fat JAR.

Exec Plugin

General-purpose plugin that can run arbitrary commands.

Maven Build Flow

The original cheat sheet visually summarizes Maven Central, the local repository, Maven lifecycle phases, and the plugins invoked for compile, test and package operations. fileciteturn2file0L82-L92

Maven Central
Plugins
Dependencies
Maven
Build Lifecycle
compile → maven-compiler-plugin → compiler:compile
test → maven-surefire-plugin → surefire:test
package → maven-jar-plugin → jar:jar
Local Repository
~/.m2/settings.xml