On this page
Maven Plugins
Maven plugins bind goals to lifecycle phases. They perform the actual build work — compiling, testing, packaging, and more.
Plugin Structure
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
<release>21</release>
</configuration>
</plugin>
</plugins>
</build>
Essential Plugins
| Plugin | Goal | Phase | Purpose |
|---|---|---|---|
maven-compiler-plugin |
compile |
compile | Compile Java source |
maven-surefire-plugin |
test |
test | Run unit tests |
maven-failsafe-plugin |
integration-test |
integration-test | Run integration tests |
maven-jar-plugin |
jar |
package | Create JAR file |
maven-war-plugin |
war |
package | Create WAR file |
maven-shade-plugin |
shade |
package | Fat/uber JAR |
Compiler Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>21</release>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Surefire Plugin (Unit Tests)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</plugin>
Shade Plugin (Fat JAR)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Running Plugin Goals Directly
mvn compiler:compile
mvn surefire:test
mvn dependency:tree
mvn clean verify
Best Practices
- Always specify plugin versions — do not rely on defaults alone
- Use
pluginManagementin parent POMs for multi-module projects - Configure Surefire and Failsafe separately for unit vs integration tests
- Use
<release>instead of separate<source>/<target>in compiler plugin - Check plugin compatibility with your Java version