Java, Maven and Gradle 25 cheatsheet

Java, Maven and Gradle 25: Maven

14 common Java, Maven and Gradle 25 tasks.

Check the Maven version

Print the Maven and Java versions it uses.

mvn -v

Create a Maven project

Generate a project from the quickstart archetype without prompts.

mvn archetype:generate -DgroupId=com.example -DartifactId=demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Compile

Compile the main source code.

mvn compile

Run the tests with Maven

Compile and run the unit tests.

mvn test

Package

Build the jar or war into target.

mvn package

Clean and install

Delete target, build, test and install the artifact into your local repository.

mvn clean install

Build with Maven without running tests

Compile and package, skipping test execution.

mvn package -DskipTests

Run one test

Run a single test method.

mvn test -Dtest=UserServiceTest#login

Show the Maven dependency tree

Print dependencies and their transitive dependencies.

mvn dependency:tree

Find dependency updates

List dependencies that have newer versions.

mvn versions:display-dependency-updates

Build one module of many

Build a module and the modules it depends on in a multi-module project.

mvn package -pl api -am

Build in parallel

Use one thread per CPU core.

mvn install -T 1C

Show the effective POM

Print the POM after inheritance and profiles are applied.

mvn help:effective-pom

Add the Maven wrapper

Add mvnw so everyone builds with the same Maven version.

mvn wrapper:wrapper

Was this page helpful?