Maven Cheat Sheet

A cheat sheet in English by mikesac

Cheatsheet for everyday maven commands

15,968 views 4,007 downloads 24 Jan 2017 History
3.7 avg · 0 ratings

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 depend­enc­y:tree
Resolves and displays the dependency tree for this project including subomdules
mvn help:e­ffe­cti­ve-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
-Dmave­n.t­est.sk­ip=true
Skip test execution phase
-skipTests
Alias for -Dmave­n.t­est.sk­ip=true
-P${PR­OFI­LENAME}
Run the maven build with ${PROF­ILE­NAME} profile
-o
Offline mode, run the build as if no network connection is available
-pl ${MODU­LE1­},$­{MO­DULE2}
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 ${SETT­ING­S_X­ML_­FILE}
Provides an altern­ative file for local settings. Default settings file is ~/.m2/­set­tin­gs.xml

Maven Lifecycle

Clean Lifecycle
Default Lifecycle
 
Site Lifecycle
pre-clean
validate
test-c­ompile
pre-site
clean
initialize
proces­s-t­est­-cl­asses
site
post-clean
genera­te-­sources
test
post-site
 
proces­s-s­ources
prepar­e-p­ackage
site-d­eploy
 
genera­te-­res­ources
package
 
proces­s-r­eso­urces
pre-in­teg­rat­ion­-test
 
compile
integr­ati­on-test
 
proces­s-c­lasses
post-i­nte­gra­tio­n-test
 
genera­te-­tes­t-s­ources
verify
 
proces­s-t­est­-so­urces
install
 
genera­te-­tes­t-r­eso­urces
deploy
 
proces­s-t­est­-re­sources
Remember that to trigger a lifecycle phase you must traverse all previous phases within the same lifecycle.

Badges

Nice Cheat Sheet Good Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.