Plugins and Goals

This lesson explains Maven's core concepts, plugins and goals.

We'll cover the following

Plugin

Maven can accept plugins to perform various tasks. The core of Maven is limited and small, a harness that leverages the intelligence of the plugins attached to it to perform various tasks. Some of the most common plugins are:

  1. Compiler Plugin: contains the logic to compile
  2. Jar Plugin: contains the logic to create jars
  3. Surefire Plugin: contains the logic to execute unit tests

There are numerous other plugins that can be used. In fact, we can even write our own plugins. Remember, plugins are nothing but code that implement the logic to perform various tasks during the build process.

Goal

A Maven plugin consists of goals which is a unit of work. You can think of it as representing the capability of a plugin. A goal is an action we want to take on the project defined by a POM (covered later) file. The following illustration shows the relationship between the different entities we’ve discussed so far.

We can examine the goals in a particular plugin using Maven’s help plugin. You can execute the commands in the widget below and see the goals printed out for the compiler plugin. The command is:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin

The output of the above command is:

The command invokes the describe goal of the help plugin specified as help:describe. The goal takes arguments from the command line, which we specify using -D. The argument -Dplugin specifies the plugin we want to get details for.

# Execute the following command to see the details for the compiler plugin
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin
# We add the argument -Ddetail and now the output gives detailed description
# of each plugin goal.
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin -Ddetail
Terminal 1
Terminal
Loading...

Interestingly, we can also list the goals of the help plugin using the help plugin itself as follows:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-help-plugin

The result will be:

In summary, Maven uses plugins to execute build tasks and each plugin consists of one or more goals.