Skip to content

Plugins

Estimated time to read: 3 minutes

Goals

Commands such as compile, clean or package are known as Goals within Maven. These are just some of the default goals.

Goals are plugins that are configured and defined within the super pom.xml file.

Project pom.xml files inherit these goals from the super pom.xml, however, these goals can be overwritten in the project pom.xml

Phases

  • validate - This validates that the project is correct and necessary. That all of the file structure and permissions are in place along with the relevant dependencies.
  • compile - Compiles source code in the project
  • test - Compiles and tests the source code, ensuring that everything is in line with the test directory
  • package - Packages code as per defined in the pom.xml file for the project

  • integration-test - Allows the application to be deployed and integration tests run

  • verify - Runs checks against the project to verify that it meets all of its requirements
  • install - Runs the package command and then copies the final package to the local repository
  • deploy - Runs the install command and then deploys the package to a corporate / remote repository

Compiler Plugin

The Compiler Plugin is used to compile the source code within the application.

Invokes javac whilst building and setting the CLASSPATH with the dependencies from the application in the pom.xml file.

The Compiler Plugin defaults to Java 1.7 as its build version. However, this can be overwritten in it's configuration within the pom.xml file. For example:

Configuration

The Compiler plugin has configuration options that include fork, Memory, source and target.

Example

     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.8.0</version>
       <configuration>
         <release>12</release> <!-- Java version -->
       </configuration>
     </plugin>

Jar Plugin

The Jar plugin is used to package the application into a Jar file. It is tied to the package phase of the Maven build cycle.

Configuration

It has minimal configuration options such as include, exclude and Manifest

Example

     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <version>3.1.2</version>
       <configuration>
        <include>**/*.xml</include>       
       </configuration>
     </plugin>

Source Plugin

The Source plugin packages source code so that it can be distributed from context-sensitive assistance from an IDE. By default, it is included in the package phase, though it is often added to the install phase.

Example

     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-source-plugin</artifactId>
       <version>3.1.0</version>
       <executions>
        <execution>
         <goals>
          <goal>jar</goal>
         </goals> 
         <phase>install</phase>
        </execution>
       </executions>
     </plugin>

Javadoc Plugin

The Javadoc plugin automatically packages any Javadocs that are within the source code. This is typically included in the package phase, though it is often added to a later phase instead.

Customisation

There are many customisation options, see here for more info

Example

     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-javadoc-plugin</artifactId>
       <version>3.1.0</version>
       <executions>
        <execution>
         <goals>
          <goal>jar</goal>
         </goals> 
         <phase>install</phase>
        </execution>
       </executions>
     </plugin>

This will output Javadocs to ./Project/target/apidocs/