Skip to content
maven-plugin-configuration logo

Maven Plugin Configuration

maven-plugin-configuration

Use when configuring Maven plugins, setting up common plugins like compiler, surefire, jar, or creating custom plugin executions.

TheBushidoCollective/han0installs199stars

SKILL.md

Full skill instructions

Maven Plugin Configuration

Master Maven plugin configuration including core plugins, build plugins, reporting plugins, and custom plugin development.

Overview

Maven plugins provide the actual functionality for building projects. Understanding how to configure plugins effectively is essential for customizing builds, optimizing performance, and ensuring code quality.

Plugin Basics

Plugin Structure

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</​groupId>
            <artifactId>maven-compiler-plugin</​artifactId>
            <version>3.12.1</​version>
            <configuration>
                <!-- Plugin-specific configuration -->
            </​configuration>
            <executions>
                <execution>
                    <id>compile-java</​id>
                    <phase>compile</​phase>
                    <goals>
                        <goal>compile</​goal>
                    </​goals>
                </​execution>
            </​executions>
        </​plugin>
    </​plugins>
</​build>

Plugin Management

<build>
    <pluginManagement>
        <plugins>
            <!-- Define versions and shared config -->
            <plugin>
                <groupId>org.apache.maven.plugins</​groupId>
                <artifactId>maven-compiler-plugin</​artifactId>
                <version>3.12.1</​version>
                <configuration>
                    <release>17</​release>
                </​configuration>
            </​plugin>
        </​plugins>
    </​pluginManagement>
    <plugins>
        <!-- Actually use plugin (inherits config) -->
        <plugin>
            <groupId>org.apache.maven.plugins</​groupId>
            <artifactId>maven-compiler-plugin</​artifactId>
        </​plugin>
    </​plugins>
</​build>

Core Build Plugins

Compiler Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-compiler-plugin</​artifactId>
    <version>3.12.1</​version>
    <configuration>
        <release>17</​release>
        <encoding>UTF-8</​encoding>
        <showWarnings>true</​showWarnings>
        <showDeprecation>true</​showDeprecation>
        <compilerArgs>
            <arg>-Xlint:all</​arg>
            <arg>-parameters</​arg>
        </​compilerArgs>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</​groupId>
                <artifactId>lombok</​artifactId>
                <version>1.18.30</​version>
            </​path>
        </​annotationProcessorPaths>
    </​configuration>
</​plugin>

Resources Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-resources-plugin</​artifactId>
    <version>3.3.1</​version>
    <configuration>
        <encoding>UTF-8</​encoding>
        <propertiesEncoding>UTF-8</​propertiesEncoding>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>pdf</​nonFilteredFileExtension>
            <nonFilteredFileExtension>ico</​nonFilteredFileExtension>
            <nonFilteredFileExtension>png</​nonFilteredFileExtension>
            <nonFilteredFileExtension>jpg</​nonFilteredFileExtension>
        </​nonFilteredFileExtensions>
    </​configuration>
</​plugin>

JAR Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-jar-plugin</​artifactId>
    <version>3.3.0</​version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</​addClasspath>
                <mainClass>com.example.Main</​mainClass>
                <addDefaultImplementationEntries>true</​addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</​addDefaultSpecificationEntries>
            </​manifest>
            <manifestEntries>
                <Build-Time>${maven.build.timestamp}</​Build-Time>
                <Built-By>${user.name}</​Built-By>
            </​manifestEntries>
        </​archive>
        <excludes>
            <exclude>**/​logback-test.xml</​exclude>
        </​excludes>
    </​configuration>
    <executions>
        <execution>
            <id>test-jar</​id>
            <goals>
                <goal>test-jar</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Source Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-source-plugin</​artifactId>
    <version>3.3.0</​version>
    <executions>
        <execution>
            <id>attach-sources</​id>
            <goals>
                <goal>jar-no-fork</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Javadoc Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-javadoc-plugin</​artifactId>
    <version>3.6.3</​version>
    <configuration>
        <doclint>none</​doclint>
        <source>17</​source>
        <quiet>true</​quiet>
        <links>
            <link>https://docs.oracle.com/​en/​java/​javase/​17/​docs/​api/</​link>
        </​links>
    </​configuration>
    <executions>
        <execution>
            <id>attach-javadocs</​id>
            <goals>
                <goal>jar</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Testing Plugins

Surefire Plugin (Unit Tests)

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-surefire-plugin</​artifactId>
    <version>3.2.3</​version>
    <configuration>
        <includes>
            <include>**/​*Test.java</​include>
            <include>**/​*Tests.java</​include>
            <include>**/​Test*.java</​include>
        </​includes>
        <excludes>
            <exclude>**/​*IT.java</​exclude>
            <exclude>**/​*IntegrationTest.java</​exclude>
        </​excludes>
        <argLine>-Xmx1024m -XX:+UseG1GC</​argLine>
        <parallel>methods</​parallel>
        <threadCount>4</​threadCount>
        <forkCount>1C</​forkCount>
        <reuseForks>true</​reuseForks>
        <systemPropertyVariables>
            <spring.profiles.active>test</​spring.profiles.active>
        </​systemPropertyVariables>
        <environmentVariables>
            <TEST_ENV>true</​TEST_ENV>
        </​environmentVariables>
    </​configuration>
</​plugin>

Failsafe Plugin (Integration Tests)

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-failsafe-plugin</​artifactId>
    <version>3.2.3</​version>
    <configuration>
        <includes>
            <include>**/​*IT.java</​include>
            <include>**/​*IntegrationTest.java</​include>
        </​includes>
        <skipAfterFailureCount>3</​skipAfterFailureCount>
    </​configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</​goal>
                <goal>verify</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

JaCoCo Plugin (Code Coverage)

<plugin>
    <groupId>org.jacoco</​groupId>
    <artifactId>jacoco-maven-plugin</​artifactId>
    <version>0.8.11</​version>
    <executions>
        <execution>
            <id>prepare-agent</​id>
            <goals>
                <goal>prepare-agent</​goal>
            </​goals>
        </​execution>
        <execution>
            <id>report</​id>
            <phase>test</​phase>
            <goals>
                <goal>report</​goal>
            </​goals>
        </​execution>
        <execution>
            <id>check</​id>
            <goals>
                <goal>check</​goal>
            </​goals>
            <configuration>
                <rules>
                    <rule>
                        <element>BUNDLE</​element>
                        <limits>
                            <limit>
                                <counter>LINE</​counter>
                                <value>COVEREDRATIO</​value>
                                <minimum>0.80</​minimum>
                            </​limit>
                            <limit>
                                <counter>BRANCH</​counter>
                                <value>COVEREDRATIO</​value>
                                <minimum>0.70</​minimum>
                            </​limit>
                        </​limits>
                    </​rule>
                </​rules>
            </​configuration>
        </​execution>
    </​executions>
</​plugin>

Quality Plugins

Enforcer Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-enforcer-plugin</​artifactId>
    <version>3.4.1</​version>
    <executions>
        <execution>
            <id>enforce</​id>
            <goals>
                <goal>enforce</​goal>
            </​goals>
            <configuration>
                <rules>
                    <requireMavenVersion>
                        <version>[3.8.0,)</​version>
                    </​requireMavenVersion>
                    <requireJavaVersion>
                        <version>[17,)</​version>
                    </​requireJavaVersion>
                    <dependencyConvergence/>
                    <requireUpperBoundDeps/>
                    <banDuplicatePomDependencyVersions/>
                    <bannedDependencies>
                        <excludes>
                            <exclude>commons-logging:commons-logging</​exclude>
                            <exclude>log4j:log4j</​exclude>
                        </​excludes>
                    </​bannedDependencies>
                </​rules>
            </​configuration>
        </​execution>
    </​executions>
</​plugin>

Checkstyle Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-checkstyle-plugin</​artifactId>
    <version>3.3.1</​version>
    <configuration>
        <configLocation>checkstyle.xml</​configLocation>
        <consoleOutput>true</​consoleOutput>
        <failsOnError>true</​failsOnError>
        <violationSeverity>warning</​violationSeverity>
        <includeTestSourceDirectory>true</​includeTestSourceDirectory>
    </​configuration>
    <executions>
        <execution>
            <id>checkstyle</​id>
            <phase>validate</​phase>
            <goals>
                <goal>check</​goal>
            </​goals>
        </​execution>
    </​executions>
    <dependencies>
        <dependency>
            <groupId>com.puppycrawl.tools</​groupId>
            <artifactId>checkstyle</​artifactId>
            <version>10.12.6</​version>
        </​dependency>
    </​dependencies>
</​plugin>

SpotBugs Plugin

<plugin>
    <groupId>com.github.spotbugs</​groupId>
    <artifactId>spotbugs-maven-plugin</​artifactId>
    <version>4.8.3.0</​version>
    <configuration>
        <effort>Max</​effort>
        <threshold>Low</​threshold>
        <xmlOutput>true</​xmlOutput>
        <excludeFilterFile>spotbugs-exclude.xml</​excludeFilterFile>
    </​configuration>
    <executions>
        <execution>
            <goals>
                <goal>check</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

PMD Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-pmd-plugin</​artifactId>
    <version>3.21.2</​version>
    <configuration>
        <rulesets>
            <ruleset>/​category/​java/​bestpractices.xml</​ruleset>
            <ruleset>/​category/​java/​errorprone.xml</​ruleset>
        </​rulesets>
        <failOnViolation>true</​failOnViolation>
        <printFailingErrors>true</​printFailingErrors>
        <includeTests>true</​includeTests>
        <targetJdk>17</​targetJdk>
    </​configuration>
    <executions>
        <execution>
            <goals>
                <goal>check</​goal>
                <goal>cpd-check</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Packaging Plugins

Assembly Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-assembly-plugin</​artifactId>
    <version>3.6.0</​version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</​descriptorRef>
        </​descriptorRefs>
        <archive>
            <manifest>
                <mainClass>com.example.Main</​mainClass>
            </​manifest>
        </​archive>
    </​configuration>
    <executions>
        <execution>
            <id>make-assembly</​id>
            <phase>package</​phase>
            <goals>
                <goal>single</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Shade Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-shade-plugin</​artifactId>
    <version>3.5.1</​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>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                </​transformers>
                <filters>
                    <filter>
                        <artifact>*:*</​artifact>
                        <excludes>
                            <exclude>META-INF/​*.SF</​exclude>
                            <exclude>META-INF/​*.DSA</​exclude>
                            <exclude>META-INF/​*.RSA</​exclude>
                        </​excludes>
                    </​filter>
                </​filters>
                <relocations>
                    <relocation>
                        <pattern>com.google</​pattern>
                        <shadedPattern>shaded.com.google</​shadedPattern>
                    </​relocation>
                </​relocations>
            </​configuration>
        </​execution>
    </​executions>
</​plugin>

WAR Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-war-plugin</​artifactId>
    <version>3.4.0</​version>
    <configuration>
        <failOnMissingWebXml>false</​failOnMissingWebXml>
        <packagingExcludes>WEB-INF/​classes/​logback-test.xml</​packagingExcludes>
        <webResources>
            <resource>
                <directory>src/​main/​webapp</​directory>
                <filtering>true</​filtering>
                <includes>
                    <include>**/​*.html</​include>
                </​includes>
            </​resource>
        </​webResources>
    </​configuration>
</​plugin>

Spring Boot Plugin

<plugin>
    <groupId>org.springframework.boot</​groupId>
    <artifactId>spring-boot-maven-plugin</​artifactId>
    <version>3.2.0</​version>
    <configuration>
        <mainClass>com.example.Application</​mainClass>
        <excludes>
            <exclude>
                <groupId>org.projectlombok</​groupId>
                <artifactId>lombok</​artifactId>
            </​exclude>
        </​excludes>
        <layers>
            <enabled>true</​enabled>
        </​layers>
        <image>
            <name>${project.artifactId}:${project.version}</​name>
            <builder>paketobuildpacks/​builder:base</​builder>
        </​image>
    </​configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</​goal>
            </​goals>
        </​execution>
    </​executions>
</​plugin>

Version Management Plugins

Versions Plugin

<plugin>
    <groupId>org.codehaus.mojo</​groupId>
    <artifactId>versions-maven-plugin</​artifactId>
    <version>2.16.2</​version>
    <configuration>
        <rulesUri>file:///${project.basedir}/​version-rules.xml</​rulesUri>
    </​configuration>
</​plugin>
# Check for updates
mvn versions:display-dependency-updates
mvn versions:display-plugin-updates
mvn versions:display-property-updates

# Update versions
mvn versions:update-properties
mvn versions:use-latest-releases
mvn versions:update-parent

Release Plugin

<plugin>
    <groupId>org.apache.maven.plugins</​groupId>
    <artifactId>maven-release-plugin</​artifactId>
    <version>3.0.1</​version>
    <configuration>
        <tagNameFormat>v@{project.version}</​tagNameFormat>
        <autoVersionSubmodules>true</​autoVersionSubmodules>
        <releaseProfiles>release</​releaseProfiles>
    </​configuration>
</​plugin>

Code Generation Plugins

Build Helper Plugin

<plugin>
    <groupId>org.codehaus.mojo</​groupId>
    <artifactId>build-helper-maven-plugin</​artifactId>
    <version>3.5.0</​version>
    <executions>
        <execution>
            <id>add-source</​id>
            <phase>generate-sources</​phase>
            <goals>
                <goal>add-source</​goal>
            </​goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/​generated-sources</​source>
                </​sources>
            </​configuration>
        </​execution>
    </​executions>
</​plugin>

Exec Plugin

<plugin>
    <groupId>org.codehaus.mojo</​groupId>
    <artifactId>exec-maven-plugin</​artifactId>
    <version>3.1.1</​version>
    <executions>
        <execution>
            <id>run-script</​id>
            <phase>generate-sources</​phase>
            <goals>
                <goal>exec</​goal>
            </​goals>
            <configuration>
                <executable>bash</​executable>
                <arguments>
                    <argument>${project.basedir}/​scripts/​generate.sh</​argument>
                </​arguments>
            </​configuration>
        </​execution>
    </​executions>
</​plugin>

Best Practices

  1. Version Pinning - Always specify plugin versions
  2. Plugin Management - Centralize in parent POM
  3. Minimal Configuration - Use defaults where possible
  4. Execution IDs - Use meaningful execution IDs
  5. Phase Binding - Bind to appropriate phases
  6. Skip Properties - Provide skip properties for flexibility
  7. Documentation - Comment complex configurations
  8. Inheritance - Use pluginManagement for multi-module
  9. Updates - Keep plugins current
  10. Profile Separation - Separate CI/​release plugins into profiles

Common Pitfalls

  1. Missing Versions - Relying on default versions
  2. Wrong Phase - Plugin bound to wrong lifecycle phase
  3. Duplicate Executions - Same goal running multiple times
  4. Memory Issues - Insufficient heap for plugins
  5. Ordering - Plugin execution order conflicts
  6. Inheritance - Unintended plugin inheritance
  7. Fork Confusion - Misunderstanding fork behavior
  8. Skip Flags - Tests accidentally skipped in CI

When to Use This Skill

  • Configuring build compilation settings
  • Setting up test frameworks
  • Configuring code quality checks
  • Creating executable JARs
  • Setting up CI/​CD builds
  • Optimizing build performance
  • Generating source code
  • Managing releases and versions

More skills from TheBushidoCollective

typescript-utility-types logo
TheBushidoCollective/han

typescript-utility-types

Use when typeScript utility types, mapped types, and advanced type manipulation. Use when creating flexible, type-safe TypeScript code.

199 0
View
shell-portability logo
TheBushidoCollective/han

shell-portability

Use when writing shell scripts that need to run across different systems, shells, or environments. Covers POSIX compatibility and platform differences.

199 0
View
tailwind-performance logo
TheBushidoCollective/han

tailwind-performance

Use when optimizing Tailwind CSS for production, reducing bundle size, and improving performance. Covers PurgeCSS, JIT mode, and build optimization.

199 0
View
figma-generate-component logo
TheBushidoCollective/han

figma-generate-component

Generate production-ready code from a Figma component or frame using the Figma MCP server

199 0
View
dialyzer-integration logo
TheBushidoCollective/han

dialyzer-integration

Use when integrating Dialyzer into development workflows and CI/CD pipelines for Erlang/Elixir projects.

199 0
View
rubocop-configuration logo
TheBushidoCollective/han

rubocop-configuration

Use when ruboCop configuration including YAML config, departments, inheritance, and customization.

199 0
View
elixir-otp-patterns logo
TheBushidoCollective/han

elixir-otp-patterns

Use when Elixir OTP patterns including GenServer, Supervisor, Agent, and Task. Use when building concurrent, fault-tolerant Elixir applications.

199 0
View
ameba-custom-rules logo
TheBushidoCollective/han

ameba-custom-rules

Use when creating custom Ameba rules for Crystal code analysis including rule development, AST traversal, issue reporting, and rule testing.

199 0
View
Swift Optionals Patterns logo
TheBushidoCollective/han

Swift Optionals Patterns

Use when swift's optional handling patterns including optional binding, chaining, nil coalescing, and modern approaches to safely working with optional values while avoiding common pitfalls and force unwrapping.

199 0
View
code-annotation-patterns logo
TheBushidoCollective/han

code-annotation-patterns

Use when annotating code with structured metadata, tags, and markers for AI-assisted development workflows. Covers annotation formats, semantic tags, and integration with development tools.

199 0
View
Scala Collections logo
TheBushidoCollective/han

Scala Collections

Use when scala collections including immutable/mutable variants, List, Vector, Set, Map operations, collection transformations, lazy evaluation with views, parallel collections, and custom collection builders for efficient data processing.

199 0
View
reactflow-custom-nodes logo
TheBushidoCollective/han

reactflow-custom-nodes

Use when creating custom React Flow nodes, edges, and handles. Covers custom node components, resizable nodes, toolbars, and advanced customization.

199 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View