Appendix D. Maven Short References – Common Commands and Archetypes

 

"Imagination is more important than knowledge..."

 
 --Albert Einstein

This chapter summarizes the most important commands and concepts covered in the book, and it provides a textual mind map of Maven. The first section summarizes Maven's commands and related parameters covered during the book. The second section reports the complete list of Maven's variables. The last paragraph shows Maven's lifecycle.

Commands

Maven can be executed by the command line to build, check dependencies and code, deploy, and release artifacts. A complete explanation of these commands can be found at http://maven.apache.org/; the following subsections explain only the most common commands.

Build

Maven will clean the workspace, compile, and install on the local repository:

$ mvn clean install

Or, alternatively, you can specify the pom.xml file's name:

$ mvn clean install –f pom.xml

This command is the standard Maven call.

$ mvn clean install –f my_pom.xml

Given the specified POM, Maven will clean the workspace, compile, and install on the local repository. Also refer to Chapter 2, Core Maven Concepts; Chapter 3, Writing Plugins; and Chapter 5, Continuous Integration and Delivery with Maven.

$ mvn clean install -DskipTests

Maven will skip all tests ( Surefire Plugin and Failsafe Plugin). Also refer to Chapter 3, Writing Plugins and Chapter 5, Continuous Integration and Delivery with Maven.

$ mvn --non-recursive clean compile

Or you can use a short notation:

$ mvn -N clean compile

Maven will clean the workspace and will compile, but it does not recurse into subprojects. It is useful to install the parent POM avoiding submodules compiling:

$ mvn -U clean compile

Maven will clean the workspace, compile, and update the local repository:

$ mvn clean install –pl my_artifact -am

Given the artifact ID, Maven will clean the workspace, compile, and install the module specified and all snapshot dependencies on the local repository. Also refer to Chapter 3, Writing Plugins, and Chapter 5, Continuous Integration and Delivery with Maven. It is useful to install a specific artifact avoiding the aggregator POM.

Deploy and release

Deploy the artifact on the remote repository configured (see the distributionManagement tag) into the given POM or parent POM or passed as parameters:

$ mvn deploy

Or, alternatively, you can specify to deploy the artifacts at the end of the multimodule build:

$ mvn deploy –DdeployAtEnd=true

You can also specify the final destination:

$ mvn deploy:deploy –DaltDeploymentRepository=http://myhost

Also refer to Chapter 2, Core Maven Concepts, and Chapter 5, Continuous Integration and Delivery with Maven. If the repository requires user access, configure the settings.xml file. The deployAtEnd parameter is useful for multimodules since Maven will deploy all project reactors at the end of the build phase:

$ mvn release:clean release:prepare

Rollback the action:

$ mvn release:rollback

The preceding command performs the release preparation (Maven release plugin) or the rollback (also refer to Chapter 5, Continuous Integration and Delivery with Maven).

$ mvn –-batch-mode -f MyMultiModule_pom.xml 
-DallowTimestampedSnapshots=true -DignoreSnapshots=true 
-DreleaseVersion=0.0.2 
release:clean release:prepare

The preceding command performs the release preparation (Maven release plugin) setting the current release version to 0.0.2 of the given multimodule POM (refer to Chapter 5, Continuous Integration and Delivery with Maven):

$ mvn scm:checkin

Or you can update the current workspace with:

$ mvn scm:update

The preceding command performs the commit or update from the current SCM (SVN and GIT) repository (refer to Chapter 5, Continuous Integration and Delivery with Maven).

Android

Maven shows the available devices, deploys the application, and launches the Android emulator:

$ mvn android:devices
$ mvn android:deploy
$ mvn android:run

Execute the following command to show all the available options:

$ mvn android:help

Miscellaneous

The following command shows the plugin's details (refer to Chapter 2, Core Maven Concepts):

$ mvn help:describe -DgroupId=MyGroupId 
                    -DartifactId=MyPlugin 
                    -Dversion=0.0.0

Generate a text reporting the project's dependency tree:

$ mvn dependency:tree

You can customize the verbosity through the following command:

$ mvn dependency:tree -Dverbose -Dincludes=MyLibrary

Through the includes parameter, we can filter only the specified packages (refer to Chapter 2, Core Maven Concepts).

$ mvn dependency:purge-local-repository

This goal is meant to delete all of the dependencies for the current project from the local repository.

$ mvn help:active-profiles

This goal shows the active profiles (refer to Chapter 4, Managing the Code).

$ mvn site

This goal generates the reports (site or FindBugs or PMD) on the target directory.

$ mvn assembly:single

This goal is executed to package the project in conjunction with the Assembly Plugin.

$ mvn package

This goal executes a custom assembly described within the descriptor file (refer to Chapter 4, Managing the Code).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset