jabrena/plinth / skills/112-java-maven-plugins
112-java-maven-plugins
VerifiedUse when you need to add or configure Maven plugins in your pom.xml — including quality tools (enforcer, surefire, failsafe, jacoco, pitest, spotbugs, pmd), security scanning (OWASP), code formatting (Spotless), version management, container image build (Jib), build information tracking, and benchmarking (JMH) — through a consultative, modular step-by-step approach that only adds what you actually need. This should trigger for requests such as Add Maven plugins in pom.xml; Improve Maven plugins in pom.xml; Configure Maven quality plugins in pom.xml; Add Maven build lifecycle plugins for Java verification; Review Maven plugin versions and executions. Part of Plinth Toolkit
references/112-java-maven-plugins-profile-cyclomatic-complexity.md
View on GitHub---
name: 112-java-maven-plugins-profile-cyclomatic-complexity
description: Cyclomatic complexity profile guidance using PMD and JXR reports.
license: Apache-2.0
metadata:
author: Juan Antonio Breña Moral
version: 0.19.0
---
# Maven Plugins: pom.xml Configuration Best Practices
## Role
You are a Senior software engineer with extensive experience in Java software development.
## Tone
Treat the user as a knowledgeable partner. Preserve existing Maven configuration, explain trade-offs, and apply this reference only when the SKILL.md question flow selected this plugin or profile.
## Goal
Configure cyclomatic complexity profile only when selected by the user in `112-java-maven-plugins`. Read this reference after the SKILL.md orchestration has validated the Maven project, analyzed existing plugins/properties/profiles, and collected the user's plugin/profile selections.
## Constraints
Apply only the selected cyclomatic complexity profile configuration and preserve existing project configuration.
- Read this reference only when the user selected the corresponding Maven plugin or profile in the centralized question flow.
- Before adding configuration, check whether the plugin, property, reporting entry, support file, or profile already exists.
- Never remove or replace existing Maven configuration without explicit user confirmation.
- Add only the Maven properties, plugin configuration, profile configuration, and support files required by this reference.
## Steps
### Step 1: Add selected Maven properties
Add only the properties needed for this selected plugin/profile. If a property already exists, preserve the current value unless the user explicitly confirms a change.
```xml
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.version>3.9.10</maven.version>
<java.version>[USER_SELECTED_JAVA_VERSION]</java.version>
<maven-plugin-pmd.version>3.28.0</maven-plugin-pmd.version>
<maven-plugin-jxr.version>3.6.0</maven-plugin-jxr.version>
```
### Step 2: Cyclomatic Complexity Analysis Profile Configuration
**Purpose**: Configure PMD-based cyclomatic complexity analysis profile to detect and report overly complex methods and classes.
**Dependencies**: Only execute if user selected "Cyclomatic Complexity" in the SKILL.md question flow. Requires completion of the SKILL.md orchestration steps and selected property handling.
**CRITICAL PRESERVATION RULE**: Only ADD this profile if it doesn't already exist. Never REPLACE or REMOVE existing profiles.
## Pre-Implementation Check
**BEFORE adding Cyclomatic Complexity profile, check if it already exists in the pom.xml:**
If `<profiles>` section with `cyclomatic-complexity` profile already exists: Ask user "Cyclomatic Complexity profile already exists. Do you want to enhance the existing configuration? (y/n)"
If user says "n": Skip this step entirely.
If user says "y": Proceed with adding missing configuration elements only.
**CONDITIONAL EXECUTION**: Only execute this step if user selected "Cyclomatic Complexity" in the SKILL.md question flow.
## PMD Ruleset Configuration File
**CREATE the PMD ruleset file BEFORE adding the profile.** Location depends on project structure:
**Mono-module projects** (no `<modules>` in pom.xml): Create `src/main/pmd/pmd-cyclomatic-complexity.xml`
**Multi-module projects** (has `<modules>` in pom.xml): Create `pmd/pmd-cyclomatic-complexity.xml` at project root
**File content** (`pmd-cyclomatic-complexity.xml`):
```xml
<?xml version="1.0"?>
<ruleset name="Cyclomatic Complexity Ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Custom ruleset for cyclomatic complexity analysis only
</description>
<!-- https://pmd.github.io/pmd/pmd_rules_java_design.html#cyclomaticcomplexity -->
<rule ref="category/java/design.xml/CyclomaticComplexity">
<properties>
<property name="classReportLevel" value="70" />
<property name="methodReportLevel" value="25" />
<property name="cycloOptions" value="" />
</properties>
</rule>
</ruleset>
```
## Cyclomatic Complexity Profile Configuration
**Use the correct ruleset path** when adding the profile:
- Mono-module: `src/main/pmd/pmd-cyclomatic-complexity.xml`
- Multi-module: `pmd/pmd-cyclomatic-complexity.xml`
**ADD this profile to the `<profiles>` section in pom.xml ONLY if it doesn't already exist:**
```xml
<!-- Cyclomatic Complexity Analysis Profile -->
<profile>
<id>cyclomatic-complexity</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<!-- PMD Plugin for Cyclomatic Complexity Analysis -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-plugin-pmd.version}</version>
<configuration>
<rulesets>
<ruleset>src/main/pmd/pmd-cyclomatic-complexity.xml</ruleset>
</rulesets>
<printFailingErrors>true</printFailingErrors>
<linkXRef>true</linkXRef>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
<execution>
<id>pmd-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>pmd-report</id>
<phase>site</phase>
<goals>
<goal>pmd</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- PMD Report Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-plugin-pmd.version}</version>
<configuration>
<rulesets>
<ruleset>src/main/pmd/pmd-cyclomatic-complexity.xml</ruleset>
</rulesets>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
<!-- JXR Plugin for Source Cross-Reference -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>${maven-plugin-jxr.version}</version>
</plugin>
</plugins>
</reporting>
</profile>
```
**For multi-module projects**: Replace `src/main/pmd/pmd-cyclomatic-complexity.xml` with `pmd/pmd-cyclomatic-complexity.xml` in both build and reporting plugin configurations.
## Usage Examples
```bash
# Run cyclomatic complexity analysis
./mvnw clean verify -Pcyclomatic-complexity
# Generate PMD reports
./mvnw site -Pcyclomatic-complexity
# View reports
open target/site/pmd.html
```
## Validation
After adding this profile, verify the configuration:
```bash
# Test Cyclomatic Complexity profile
./mvnw clean verify -Pcyclomatic-complexity
```
#### Step Constraints
- **MUST** only add Cyclomatic Complexity profile if "Cyclomatic Complexity" was selected in the SKILL.md question flow
- **MUST** create PMD ruleset file before adding the profile
- **MUST** use mono-module path (src/main/pmd/) or multi-module path (pmd/) based on project structure
- **MUST** check if profile already exists before adding
- **MUST** ask user permission before modifying existing profile configuration
- **MUST** use selected version properties for plugin versions
- **MUST** skip this step entirely if Cyclomatic Complexity was not selectedRelated skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 193k | Updated | Claude CodeCodex | Verified | Install |