Saturday, October 8, 2016

How to run maven

mvn command

The syntax for running Maven is as follows:

mvn [options] [<goal(s)>] [<phase(s)>]

The order of execution depends on the order in which the goals and the build phases are invoked.

Running maven phases

Example: build a Maven project with the package phase of the default life cycle

mvn package

Example: install in local repository

mvn clean install

Above you see the most common build invocation for a Maven project. The command mvn clean install creates the package and install it in the local repository for re-use from other projects. This command executes each default life cycle phase prior to install, in order, before executing install.

Example: deploy to shared repository

mvn clean deploy

In a build environment, the call mvn clean deploy clean, build and deploy artifacts into the shared repository. When the command is used in a project with one or more sub-projects, Maven traverses every subproject to clean, build and then executes deploy.

Running maven goals

A build phase can also have zero or more goals bound to it. If a build phase has no goals bound to it, that build phase will not execute. If it has one or more goals bound to it, it will execute all those goals

Example: call generate goal with archetype plugin

mvn archetype:generate

Example: call check goal with checkstyle plugin

mvn checkstyle:check

Example: call copy-dependencies goal before the package phase

mvn clean dependency:copy-dependencies package

The clean and package arguments are build phases, while the dependency:copy-dependencies is a goal of a plugin.
The clean phase is executed first (comprising of all preceding phases of the clean lifecycle), then the dependency:copy-dependencies goal, finally is executed the package phase (and all its preceding build phases).

No comments :

Post a Comment