Maven PMD "You have N PMD violations" - Fix the Quality Gate in CI
The maven-pmd-plugin ran its rulesets (or the CPD copy-paste detector) and found violations at or above the configured failurePriority. The pmd:check/pmd:cpd-check goal failed the build deliberately - a code-quality gate.
What this error means
The build fails with You have N PMD violations. For more details see: target/pmd.xml, or You have N CPD duplication(s), listing each rule and location.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-pmd-plugin:3.22.0:check (default) on project app:
You have 4 PMD violations. For more details see:
/workspace/target/pmd.xmlCommon causes
New code breaks PMD rules
Empty catch blocks, unused variables, overly complex methods, or other ruleset violations were introduced, and the check fails on them.
CPD found duplicated code
The copy-paste detector found a block exceeding the minimumTokens threshold duplicated across files, failing cpd-check.
How to fix it
Read the report and fix the violations
Run the check locally; the report names each rule and location.
mvn -B pmd:check
# reports: target/pmd.xml and target/cpd.xmlTune the failure priority or suppress narrowly
Adjust which priorities fail the build, or suppress a specific rule with an annotation/comment where justified.
<configuration>
<failurePriority>3</failurePriority>
<rulesets>
<ruleset>/category/java/bestpractices.xml</ruleset>
</rulesets>
</configuration>How to prevent it
- Run PMD locally / in pre-commit to catch violations before CI.
- Pin the plugin and ruleset versions so rules do not drift.
- Keep suppressions specific and reviewed.