Task 2: Getting Help with Maven

Once you have Maven installed, most everything you do with it will be done by using the mvn command, some options for that command and one or more Goals and/or Phases that you pass in. The mvn command itself is actually a small shell script that looks for your Java installation (via the environment variable JAVA_HOME), your Maven installation (via M2_HOME), and then uses Java to execute Maven's main class along with the options and commands you've sent it.

Simply typing mvn by itself will present you information for commonly used build commands. Unfortunately this assumes you already have a Maven project, so it's a little misleading. It does offer up the --help (or -h) command-line argument for getting usage information. The --version and -v options will display the version of Maven you're running:

To get information about plugins, your project's POM and environment settings, Maven uses the help plugin. To get information on the help plugin itself, use the help:help goal.

To get a detailed description on the goals listed by help:help, set the goal property to the goal you are interested in and add the detail property to true. You can set properties by adding -Dproperty=value on the command-line.

Display the version of Maven you're using

prompt> mvn -v
Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
Maven home: /Users/brian/Applications/apache-maven-3.0.3
Java version: 1.6.0_22, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
...etc...

Display command-line options for Maven

prompt> mvn -h
usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make ...    
 -amd,--also-make-dependents ...
...etc...

Get information about the help plugin

prompt> mvn help:help
...
Maven Help Plugin
  The Maven Help plugin provides goals aimed at helping...

This plugin has 9 goals:

help:active-profiles
  Displays a list of the profiles which are currently active for this build.
...

Get information about a specific help goal

prompt> mvn help:help -Dgoal=describe -Ddetail=true
...
help:describe
  Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo -
  Maven plain Old Java Object).

  Available parameters:

    artifactId
      The Maven Plugin artifactId to describe.
...