Skip to content

MavenCommandReference

Marcin Kuthan edited this page Mar 27, 2015 · 1 revision

Introduction

The document is Maven commands reference. It is organized as sections, each section for one build aspect. Commands listed below cover 90% typical use-cases. Few commands are supported only by Maven 3.

Project build

Clean a project:

mvn clean

Compile a project:

mvn compile

Run unit tests (it also compiles a project):

mvn test

Build a package (it also executes unit tests):

mvn package

Run integration test (it also builds a package):

mvn verify

Project run

Run Java EE application on local server (Tomcat):

mvn tomcat6:run

For modular projects:

mvn -pl modular-war-webapp tomcat6:run -am

Project deployment into local repository

Notice:

Goal 'install' should not be called frequently (see install antipattern).

Install a package into local repository (it also runs integration tests):

mvn install

Install an artifact into local repository (skip integration test execution):

mvn -DskipITs=true install

Install an artifact into local repository (skip unit and integration test execution):

mvn -DskipTests=true install

Project deployment into remote repository

Notice:

Goal deploy should not be called directly. Configure build plan on continuous integration server to deploy artifact into corporate enterprise repository.

Deploy artifact into enterprise repository:

mvn deploy

Site generation

Notice:

For modular Maven projects all modules must be installed in the local repository before site generation (issue 12).

Generate site without tests reports (tests are not executed):

mvn site:site

Generate site with unit tests reports:

mvn test site:site

Generate site with unit and integration tests reports:

mvn verify site:site

Generate site stage with valid links between project modules (for modular projects site stage is broken, look at issue 9):

mvn test site:site site:stage

or

mvn verify site:site site:stage

Code quality analysis

Analyse code quality with Sonar:

mvn clean install -DskipTests=true
mvn sonar:sonar

Read Sonar configuration guide.

Code coverage reporting

Notice:

It is much more feasible to generate code coverage reports directly from IDE than from Maven. Write test, write code, run coverage for separated test, and check that all important branches are covered.

Generate Clover reports for unit tests:

mvn clover2:setup test clover2:aggregate clover2:clover

Generate clover reports for unit and integration tests:

mvn clover2:setup verify clover2:aggregate clover2:clover

Read Clover configuration guide.

Dependency Management

Check dependencies for newer versions:

mvn versions:display-dependency-updates

Check plugins for newer versions:

mvn versions:display-plugin-updates

Check for newer versions defined as properties:

mvn versions:display-property-updates

Display project dependencies:

mvn dependency:tree

Analyze project dependencies:

mvn dependency:analyze

Getting Help

Display effective Maven settings:

mvn help:effective-settings

Display effective POM:

mvn help:effective-pom

Display all profiles (from settings.xml and POMs hierarchy):

mvn help:active-profiles

Display plugin goals (for m-compiler-p in the example below):

mvn compiler:help

Display plugin's goal description (for goal compile in m-compiler-p in the example below):

mvn compiler:help -Dgoal=compile -Ddetail