Show Menu

Maven Cheat Sheet by

Cheatsheet for everyday maven commands
maven     mvn

Cleanup commands

mvn clean
Delete target folder in the project including submod­ule's ones

Compile commands

mvn clean compile
Compile all code without running any test
mvn clean test
Compile source code and test code and executes Unit Test
mvn clean package
Compile source code and test code, executes unit test, if all tests pass, it package compiled code in output archive
mvn clean verify
Compile source­/test code, executes unit test, package compiled code and then executes Integr­ation tests

Deploy commands

mvn clean install
Executes full compile steps and, if all test are succesful, deploy the resulting artifact into local maven repository
mvn clean deploy
Executes full compile steps and, if all test are succesful, deploy the resulting artifact into local maven repository and deploy to remote maven repository if configured

Resolution commands

mvn dependency:tree
Resolves and displays the dependency tree for this project including subomdules
mvn help:effective-pom
Resolves and display the full pom hierarcy and displays it as a single pom

Additional options

-U
Re-eva­luate SNAPSHOTS depene­ncies. If a newer snapshot is found on the repository it wull be re-dow­nloded. Uneffe­ctive for stables versions
-Dmaven.test.skip=true
Skip test execution phase
-skipTests
Alias for -Dmaven.test.skip=true
-P${PROFILENAME}
Run the maven build with ${PROF­ILE­NAME} profile
-o
Offline mode, run the build as if no network connection is available
-pl ${MODULE1},${MODULE2}
Run the build just on the given list of submodule. It can be a comma separated list of submodules directory or groups­Id:­art­ifactId values
-s ${SETTINGS_XML_FILE}
Provides an alternative file for local settings. Default settings file is ~/.m2/settings.xml

Maven Lifecycle

Clean Lifecycle
Default Lifecycle
 
Site Lifecycle
pre-clean
validate
test-compile
pre-site
clean
initialize
process-test-classes
site
post-clean
generate-sources
test
post-site
 
process-sources
prepare-package
site-deploy
 
generate-resources
pack­age
 
process-resources
pre-integration-test
 
comp­ile
integration-test
 
process-classes
post-integration-test
 
generate-test-sources
verify
 
process-test-sources
inst­all
 
generate-test-resources
deploy
 
process-test-resources
Remember that to trigger a lifecycle phase you must traverse all previous phases within the same lifecycle.

Download the Maven Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/mikesac_maven.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Bash Dev Cheat Sheet

          More Cheat Sheets by mikesac

          Base Git Cheat Sheet
          Gitflow Cheat Sheet