Now that we explored the concepts of lifecycle and phase, we have to answer questions such as what is executed in each phase and how we can customize the build process in order to accomplish the desired results. To answer these questions, we need to speak of goals.
A goal is a task contained in a Maven plugin. It can be invoked by directly running the following command:
$ mvn <plugin-prefix>:<goal-name>
For example, from the /transportation-project/transportation-acq-ejb
directory, we can run the following command:
$ mvn compiler:compile [INFO] Scanning for projects... [...] [INFO] -------------------------------------------------------------- [INFO] Building transportation-acq-ejb 0.0.1-SNAPSHOT [INFO] -------------------------------------------------------------- [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-cli) @ transportation-acq-ejb --- [INFO] Compiling 2 source files to ~/transportation-project/transportation-acq-ejb/target/classes [INFO] -------------------------------------------------------------- [INFO] BUILD SUCCESS
We can see that, in this case, Maven just compiles the Java sources. So, we can invoke the Maven executable by specifying a phase, a goal, or both. In fact, if we ask for help on the command line, we obtain the following output:
$ mvn -h usage: mvn [options] [<goal(s)>] [<phase(s)>]
We can list the available goals of a certain plugin through the Maven Help Plugin. For example, we can type on the command line:
$ mvn help:describe –Dplugin=compiler [...] Name: Maven Compiler Plugin Description: The Compiler Plugin is used to compile the sources of your project. Group Id: org.apache.maven.plugins Artifact Id: maven-compiler-plugin Version: 3.1 Goal Prefix: compiler This plugin has 3 goals: compiler:compile Description: Compiles application sources compiler:help Description: Display help information on maven-compiler-plugin. Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display parameter details. compiler:testCompile Description: Compiles application test sources. For more information, run 'mvn help:describe [...] -Ddetail'
With the –Ddetail
parameter, we'll get information about the available parameters that can be specified through the –D<parameter name>
syntax in case of direct invocation of the plugin goals. We can also try the following command:
$ mvn help:describe –Dplugin=help
This way, we'll obtain help on the Maven Help Plugin!