
David Hasselhoff: Baywatch Deaths, Sobriety, and Life Now
If you have ever had a Maven build fail right at the finish line, you know the particular frustration of a red BUILD FAILURE when the tests have already passed. A common culprit for this is the PMD quality gate, which can halt a release over code style or a hidden copy-paste block, not a broken test.
Key Facts
- The build fails due to a
MojoFailureExceptionthrown by the Maven PMD plugin’scheckgoal, not a unit test failure. (Violation Checking Example) - Violations are read from a generated PMD XML report, which is the standard output of the
pmdgoal. (PMD Mojo Docs)
- The build reaches the
verifyphase, where the plugin’scheckgoal is bound, and the build fails at that specific point. (Violation Checking Example) - The failure is in the
verifyphase, not during test execution, which is a key diagnostic signal. (PMD Mojo Docs)
- The error message includes the path
target/pmd/pmd.xml, which is the default output location for the PMD plugin. (PMD Mojo Docs) - The documentation for the violation checking goal explicitly mentions this report, confirming it is the source of the rule violations. (Violation Checking Example)
- Remediation involves either fixing the violations in the XML report or configuring the plugin to stop failing the build, e.g., by relaxing rules or setting
failureReporting. (Usage Docs) - The plugin’s usage documentation provides the exact
artifactIdandversionfor configuration, clarifying the setup. (Plugin Home)
The PMD plugin in Maven is a static code analysis tool that can run during the build process. When a project has strict quality gates, the plugin can be configured to break the build if it finds too many violations. This is a common practice for teams aiming for high code standards, but it can lead to the frustrating “build passed tests but failed on style” scenario.
Understanding the Build Failure Chain
The failure chain begins with mvn verify, which triggers a sequence of lifecycle phases. After compilation and unit tests, the verify phase is reached, where the PMD plugin’s check goal is bound to run. This check goal is different from the pmd goal that simply generates a report. The check goal actively verifies the report against a set of rules and can throw an error, which, in our case, is a MojoFailureException, to fail the build.
The Violation Checking documentation states: “The pmd:check goal can fail the build if violations are found in the PMD report.” This is precisely the behavior we see in the failure chain. A MojoFailureException in this context means the code quality checks dictated by PMD have not been met, explicitly pointing to the target/pmd/pmd.xml file as the source of truth.
This setup is by design. The Violation Checking – Apache Maven PMD Plugin documentation states that the pmd:check goal can fail the build if violations are found in the PMD report. The documentation for the Apache Maven PMD Plugin further explains that this goal is designed to enforce code quality rules during the verify phase, ensuring that only code meeting the defined standards gets built. The build chain is essentially: compile → test → generate PMD report → check that report → fail if issues are found.
The “check” is the gatekeeper. It is what transforms a report from an informational document into a strict rule set. The MojoFailureException is the enforcement mechanism. The plugin’s design is to be strict, and this strictness is configurable, but by default, a build with violations will fail, as noted in the Violation Checking documentation.
For a developer, the immediate reaction to this failure is to think a unit test broke, but the log often shows tests passed. The clue is the MojoFailureException from maven-pmd-plugin. It is a clear signal to open target/pmd/pmd.xml to see the list of violations. These can range from unused variables and empty blocks to more complex design issues like copy-paste code, which the Copy/Paste Detector (CPD) within PMD identifies.
The implication is that PMD acts as a strict gatekeeper, enforcing code quality standards before deployment.
The Role of PMD Version 7.26.0 and Maven Plugin 3.28.0
This specific failure chain is common with Maven PMD plugin 3.28.0. According to the Apache Maven PMD Plugin page, version 3.28.0 is the current stable release, and it’s likely the one in use. The plugin bundles PMD 7.26.0, which, according to the PMD Release Notes, is a minor release announced on 29-June-2026. This indicates a recent, actively maintained toolchain.
The Maven PMD plugin documentation warns that the check goal can be strict. The Upgrading PMD at Runtime page explains how to override the embedded PMD version, which is a common need when a project requires a specific rule fix. In our scenario, the failure is tied to the standard PMD 7.26.0 ruleset, which includes checks for code size, naming, and potential bugs. The MojoFailureException is the direct result of these checks failing.
The configuration for this is straightforward. The Usage – Apache Maven PMD Plugin documentation shows that the plugin’s artifactId is maven-pmd-plugin and it’s placed in the build or reporting section of the POM. The check goal is bound to the verify phase. This binding is essential because it means the check occurs after all tests have run, but before the project is installed or deployed. The check goal reads the XML report (pmd.xml), which is generated by the pmd goal. If that report shows violations, the build stops.
According to the PMD Mojo documentation, the check goal is designed to be used from the command line or during the build lifecycle, typically at the verify phase. The reported violations are the direct cause of the MojoFailureException. The error message, referencing the target/pmd/pmd.xml file, is the developer’s map to the problem.
The pattern is clear: the PMD plugin’s check goal is the enforcement mechanism, and the XML report is its evidence.
The Plugin’s Check Goal in Practice
The Maven PMD plugin’s check goal is not just a report; it’s an enforcement mechanism. The Violation Checking documentation provides a concrete example of binding both pmd:check and cpd-check to the verify phase. This is a common and recommended pattern that directly leads to the failure chain described.
This strictness is configurable. The plugin’s configuration allows for failureReporting, which can be set to false to prevent the build from failing. However, many teams leave it at the default true to enforce rules. The Apache Maven PMD Plugin documentation details how the
pmdgoal generates the XML output, which is thetarget/pmd/pmd.xmlfile we see in the error.
The Maven PMD Plugin page also clarifies that the check goal does not generate the report; it only analyzes an existing one. This is a two-step process. First, the pmd goal generates the report in the target/pmd/ directory. Second, the check goal acts on that report. The check goal can also be configured to only fail if the number of violations is above a certain threshold, but the default is to fail on any violation.
This two-step process is the crux of the matter. The build failure is not a bug; it’s a feature. The PMD XML report is a map of the work that needs to be done, and the MojoFailureException is the reminder that the build won’t get to the finish line until that work is done.
The catch is that this two-step process means the build will not proceed until the PMD report is clean or the rules are adjusted.
From Failure to Fix: Adjusting Your POM
When you’re staring at a MojoFailureException caused by PMD, the immediate need is to get a passing build. The first step is to open the target/pmd/pmd.xml file and look at the specific PMD rule violations. The report will list the file names, line numbers, and the violated rule name. This is the same report the build failed on, so the data is right there.
Once you have the list, you have two primary options. One is to fix the code violations. This is the “right” way and is recommended for teams that want to maintain high standards. For each violation, you fix the underlying code issue. The docs for the Usage – Apache Maven PMD Plugin page show how the plugin fits into the build lifecycle. The second option is to configure the plugin to be less strict. This is a pragmatic, though sometimes controversial, approach. You can adjust the rulesets in the plugin configuration to exclude certain checks, or you can set a failureThreshold to allow a certain number of violations before failing the build.
The POM snippet below shows a minimal configuration for the PMD plugin. This is what allows the check to be bound. Note the phase and goals elements are defined explicitly to ensure it runs in the right lifecycle phase.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.28.0</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This configuration binds the check goal to the default verify phase. When you run mvn verify, the PMD plugin will run its analysis. If violations are found, the build fails with the PMD XML report as the clue. The Apache Maven PMD Plugin documentation states that this goal is “designed to be used from the command line or during the build lifecycle, typically at the verify phase.”
If you want to fix the issue quickly by disabling the fail behavior, you can add the failureReporting parameter. The following snippet shows how to change it to false. It’s worth noting that this is a blunt instrument and is often met with resistance in code reviews.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.28.0</version>
<configuration>
<failureReporting>false</failureReporting>
</configuration>
<executions>
<execution>
<goals><goal>check</goal></goals>
</execution>
</executions>
</plugin>
This is a clear example of how to use the plugin configuration to change the build outcome. The choice between fixing violations and relaxing the check is a decision for the development team, but the Maven PMD plugin gives you the power to do either.
The Maven PMD plugin’s check goal is a two-step process: first the pmd goal generates a report, then the check goal fails the build if that report contains violations, using the PMD Mojo Docs as the reference for the report path.
Balancing code quality enforcement with delivery speed requires teams to understand how to configure the PMD plugin effectively.
The Critical Check: the XML Report
The PMD XML report is the ground truth in this scenario. The plugin can be configured to run in a way that doesn’t fail the build, but it will always generate this report when the pmd goal runs. The Apache Maven PMD Plugin documentation specifies that the format parameter can be set to xml to generate the report, and it is the default output from the check goal.
In our example, the error
MojoFailureExceptionis thrown. This is a Maven-specific exception that indicates a problem with the build process, not a Java compilation error or a JUnit assertion failure. The Violation Checking documentation confirms that this is the standard behavior for thecheckgoal when it detects violations. The failure of the build is the “stick,” and the report is the “carrot” – it points you to what needs to be fixed.
For a developer, this means the workflow is: run the build, see the failure, open the XML report, analyze the violations, fix the code, and re-run. The XML report is not just a file; it’s the bridge between the abstract concept of “quality gate” and the concrete reality of a codebase. It’s the actionable output of the PMD plugin.
Ultimately, the XML report is the actionable artifact that bridges the gap between a failing build and a successful commit.
Related reading: **Pierce Brosnan Biography: Tragedy, Family, and Irish Roots** · **Rick Moranis: Tragedy, Career Break, Net Worth & Comeback**
maven.apache.org, maven.apache.org, pmd.github.io, maven.apache.org, pmd.github.io, sourceforge.net, pmd.github.io, x.com, central.sonatype.com
Frequently asked questions
Is the PMD plugin causing the build to fail, not the unit tests?
Yes, in this exact scenario, the PMD plugin’s check goal throws a MojoFailureException after the tests pass. This is a distinct failure from a test failure, and it’s caused by code quality violations that PMD has identified.
How do I know if PMD is the reason my build failed?
If the build log shows a MojoFailureException from the maven-pmd-plugin (or cpd-check) and refers to target/pmd/pmd.xml, then PMD is the cause. The error message will explicitly state the violation count and point to the XML report.
What exactly is target/pmd/pmd.xml?
It is the output file generated by the PMD plugin. This file contains a structured list of all rule violations, including the file path, line number, and a message about what’s wrong, per the PMD Mojo Docs documentation.
Can I configure the PMD plugin to not fail the build?
Yes. You can set the failureReporting parameter to false or adjust the failureThreshold to allow a certain number of violations. However, this reduces the effectiveness of the quality gate. Best practice is to fix the violations.
I see cpd-check in the docs. What’s that?
cpd-check is another goal of the PMD plugin that checks for copy-paste detected code. It’s a separate check from the main code style checks, and it also uses the XML report to fail the build.
How do I see the violations that are causing the failure?
Open the target/pmd/pmd.xml file in a text editor or web browser. It’s more readable if you open it in your IDE’s PMD plugin, which can render the XML in a friendly format. Otherwise, a simple text editor will do.
The PMD plugin, while strict, provides a clear path to resolution through its generated reports. Fixing the violations is the most direct way to ensure a smooth build process.