Maven Cheat Sheet
Maven Command Execution Phases
To clean the target directory.
mvn clean
To validate if the project is correct
mvn vlidate
To compile the source code.
mvn compile
To run tests.
mvn test
To package compiled code in distributable format.
mvn package
To verify the maven package is valid.
mvn verify
To install package into the local repository
mvn install
To copy maven package to remote repository
mvn deploy
Create new Maven Project
To create a new Maven project in interactive mode.
mvn archetype:generate \
-DgroupId=com.mydomain \
-DartifactId=example-project
To create a new Maven project in non-interactive mode.
mvn archetype:generate \
-DgroupId=com.mydomain \
-DartifactId=example-project \
-DinteractiveMode=false
To create a new Maven web project.
mvn archetype:generate -DgroupId=com.mydomain \
-DartifactId=example-webproject \
-DarchetypeArtifactId=maven-archetype-webapp
Packaging and Installing Maven Project
To package your Maven project.
mvn package
To clean the target directory.
mvn clean
To clean target directory and package your project.
mvn clean package
To execute your build with five concurrent threads for package.
mvn clean package -T 5
To package a specific module.
mvn clean package -pl my_module
To package multiple module
mvn clean package -pl first_module,second_module
To package without running tests.
mvn clean package -DskipTests
To skip tests and compile while packaging.
mvn clean package -Dmaven.test.skip=true
To run a single tests
mvn test -Dtest="name_of_your_test"
To run build offline.
mvn clean package -o
Dependencies
To list all dependencies.
mvn dependency:list
To check a specific dependency in project.
mvn dependency:list | grep testng
To see plugins used in project.
mvn dependency:resolve-plugins
To see the plugin updates for project.
mvn versions:display-plugin-updates
Sources
To download source code for each of the dependencies in your pom file.
mvn dependency:sources
To download the sources matching specific groupId.
mvn dependency:sources -DincludeGroupIds=org.testng
To download the javadocs.
mvn dependency:resolve -Dclassifier=javadoc
Miscellaneous
To see the dependency tree.
mvn dependency:tree
To analyze the dependencies of the project.
mvn dependency:analyze
To describe the attributes of a plugin
mvn help:describe
To display the effective POM.
mvn help:effective-pom
Command options
To specify number of threads
-T
To specify threads per CPU.
-T 3C
To resume build from the specific project
-rf
To build specific module
-pl
To enable debug output
-X
To activate the profile
-P
To stop at first failure.
--ff