Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Configure Maven to run tests, collect JaCoCo coverage, and enforce static-analysis rules; configure Jenkins to run that build and publish its reports. The distinction matters: Jenkins displays coverage data generated by Maven and JaCoCo—it does not create coverage just because a reporting plugin is installed.
Put build checks in Maven and report presentation in Jenkins
Keep repeatable tests, coverage instrumentation, analysis tools, and their rules in the project’s pom.xml. That lets developers run the same checks locally and in CI. Use Jenkins to select the JDK and Maven environment, run the lifecycle, set build status, and expose the resulting reports.
Coverage describes which code ran during tests; it does not establish that tests have useful assertions or that the code is correct. Static analysis checks source or bytecode against configured rules. Tools such as Checkstyle, PMD, and SpotBugs have different focuses, so they are complementary choices rather than interchangeable measures.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Check Jenkins and Maven prerequisites
- A Jenkins Pipeline-capable job and an agent with a compatible JDK and Maven installation. A Maven Wrapper (
./mvnw) can select the Maven distribution from the repository; alternatively, use a preconfigured Jenkins tool or an installedmvn. - A source-controlled
Jenkinsfile. In Declarative Pipeline, names in thetoolsdirective must already be configured in Jenkins. The Pipeline Maven Integration plugin is optional; it is useful for managed Maven settings and tool integration, but a basic pipeline can invoke Maven directly. Its Maven and JDK installers do not work inside Docker/container execution, where tools need to be present in the image. See Jenkins Pipeline syntax, Jenkinsfile guidance, and Pipeline Maven steps. - The usual Jenkins Pipeline and JUnit reporting steps, plus one optional coverage publisher: the general-purpose Coverage plugin or the JaCoCo-specific plugin. Install the plugin that matches the pipeline shown below; do not publish the same report through both without a reason.
JaCoCo’s Maven documentation currently describes Maven 3.0+ and Java 8+ as prerequisites for its Maven plugin. Compatibility depends on the JaCoCo release and project runtime, so check the selected release’s documentation rather than treating those minimums as a recommendation for every project. JaCoCo Maven plugin documentation
#1 Best Overall
Configure JaCoCo in the POM
JaCoCo’s prepare-agent goal sets a Maven property—normally argLine—that passes its Java agent to the test JVM. The agent records execution data; JaCoCo’s report goal turns that data into reports. The following is a template, not a universal drop-in configuration: select and pin a released version compatible with the project’s Maven and JDK, and ensure the XML report is enabled for the version and setup you use.
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>REPLACE_WITH_A_PINNED_COMPATIBLE_VERSION</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
JaCoCo’s report goal is bound by default to Maven’s verify phase, which is why mvn clean verify is a useful CI command. The HTML report’s documented example path is target/site/jacoco/index.html. Enable or configure XML output if the Jenkins publisher needs jacoco.xml; confirm the actual file exists before setting a report pattern. JaCoCo change history
Preserve the agent when Surefire sets JVM arguments
If Surefire defines its own argLine, it can replace JaCoCo’s agent argument. Preserve the property with Surefire’s late-evaluation form, @{argLine}, in the configured JVM arguments. Where JaCoCo is not active but a Surefire configuration still references @{argLine}, an empty default for that property can prevent an unresolved literal from being passed to the JVM. Do not set Surefire’s forkCount to 0 (or legacy forkMode to never) when relying on JaCoCo’s agent: without a forked test JVM, the agent does not run and coverage is not recorded. JaCoCo prepare-agent goal
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #2
Add static analysis and choose when it blocks a build
Generating a report and enforcing a rule are separate actions. Configure the tool and its rules in Maven, then bind enforcement goals to a lifecycle phase or call them explicitly in CI. An execution under POM <reporting> does not, by itself, configure a build execution; for Checkstyle enforcement, define the goal under <build>. If developers run only mvn test, a check bound to verify will not run locally with that command.
- Checkstyle:
checkstyle:checkstylegenerates a report;checkstyle:checkchecks violations and can fail the build. ItsfailOnViolationdefault istrue;failsOnErroris a separate setting for immediate failure. Checkstyle usage, Checkstyle check goal, Checkstyle FAQ - PMD: PMD has report goals and separate enforcement goals, including
pmd:checkandpmd:aggregate-pmd-check. Its Maven plugin documentation surfaced version 3.28.0; treat that as a documented version, not a timeless latest-version claim. Maven PMD plugin goals - SpotBugs: The
spotbugsgoal analyzes code;checkfails the build when bugs are found. The stable Maven documentation states Maven 3.6.3+ and Java 11+ for analysis; verify compatibility with the specific plugin release selected. SpotBugs Maven documentation
When introducing checks to a repository with existing findings, begin by making reports visible or establish a baseline before turning every existing violation into a failure. Then set a deliberate policy: warnings or an unstable Jenkins result where supported, or a hard failure for violations the team is ready to prevent. Thresholds are project decisions, not universal percentages. Jenkins Coverage can apply coverage quality gates, including gates that mark a build unstable; Maven analyzer checks generally enforce their configured rules through their own goals. Jenkins Coverage plugin
Run Maven and publish results from a Jenkinsfile
This baseline runs the Maven build, publishes Surefire test XML, records JaCoCo XML with the Jenkins Coverage plugin, and archives site reports for download. It assumes the POM generates XML at the indicated path and that the Coverage plugin is installed. Adjust commands, tool selection, and report patterns to your agent and workspace.
Rank #3
pipeline {
agent any
stages {
stage('Build, test, and analyze') {
steps {
sh './mvnw -B -V clean verify'
}
}
}
post {
always {
junit testResults: '**/target/surefire-reports/*.xml',
allowEmptyResults: false
recordCoverage tools: [[parser: 'JACOCO',
pattern: '**/target/site/jacoco/jacoco.xml']]
archiveArtifacts artifacts: '**/target/site/**',
allowEmptyArchive: true
}
}
}
Replace ./mvnw with mvn if Maven is installed on the agent and that is the project’s chosen setup. The -B option runs Maven in batch mode and -V prints version information. If the POM does not bind analysis goals into verify, add those goals to the build configuration or command; clean verify alone does not run unbound Checkstyle, PMD, or SpotBugs checks.
Free tools Windows power users keep installed
One-click scans. No signup required.
Publish test results even when the build fails
Jenkins’ junit step archives JUnit-format XML, and the post { always { ... } } block attempts publication regardless of the Pipeline’s completion status. Surefire normally writes to target/surefire-reports; the glob above is a common Maven-reactor pattern, not a guarantee for every project. If Failsafe integration tests are enabled, include their actual XML path too. A missing report can make publication fail; do not silently treat missing test output as success. Jenkins test and artifact recording, Surefire test goal and report directory, Jenkins Pipeline post conditions
Choose one coverage publisher
The recordCoverage step requires Jenkins’ general Coverage plugin, which parses reports generated in the workspace; it does not run JaCoCo. The explicit XML pattern is useful when the project layout differs from default matching. For a JaCoCo-only setup, the separate Jenkins JaCoCo plugin provides a jacoco Pipeline step and its own report patterns and threshold options instead. Consult the installed plugin’s Snippet Generator for exact syntax and parameters: step availability and details depend on what Jenkins has installed. Coverage plugin, Coverage Pipeline step, JaCoCo Pipeline step
archiveArtifacts can retain HTML reports such as target/site/jacoco/index.html as downloadable build artifacts. This is basic Jenkins file archival, not a replacement for a dedicated artifact repository. The Pipeline Maven Integration plugin can publish Maven-generated JaCoCo or Cobertura coverage only when the Jenkins Coverage plugin is installed; without it, that report is ignored. Jenkinsfile artifact archival, Pipeline Maven Integration plugin
Adapt the setup for integration tests and Maven reactors
Keep unit and integration test reports distinct
Surefire generally runs unit tests; Failsafe is commonly used for integration tests. The JUnit glob in the example collects Surefire reports only. Add the Failsafe report directory only when the project configures and runs Failsafe. Likewise, integration-test coverage is not automatic: configure JaCoCo’s integration report goal and the relevant test execution deliberately. JaCoCo documents separate unit and integration reporting, as well as report-integration and report-aggregate goals. JaCoCo Maven plugin documentation
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Choose per-module or aggregate coverage
In a multi-module build, each module can produce its own XML report, often matched by **/target/site/jacoco/jacoco.xml. That pattern is suitable only if it matches the actual workspace layout. For one combined report, configure report-aggregate and the reactor relationships it needs; aggregation does not happen automatically. An aggregate percentage is calculated from covered and missed elements across the included code, so it need not equal a simple average of module percentages.
Best Value
For multi-module unit tests, a glob such as **/target/surefire-reports/*.xml commonly finds module results. Verify both test and coverage patterns against files in the agent workspace; nested builds, customized report directories, and modules without reports can change what a glob matches. JaCoCo Maven plugin documentation, Coverage Pipeline step and report paths
Troubleshoot missing reports and misleading build results
- Confirm the build ran the expected tests. Check the console output for Surefire or Failsafe execution and whether tests were skipped. A skipped test suite cannot produce meaningful test coverage.
- Check JaCoCo instrumentation. Look for the JaCoCo agent argument in the test JVM invocation. Confirm tests fork a JVM and that custom Surefire JVM arguments preserve JaCoCo’s
argLine. JaCoCo warns that non-forked tests produce no agent coverage. JaCoCo Maven plugin documentation, JaCoCo prepare-agent goal - Inspect generated files before changing thresholds. In the workspace, check for JaCoCo execution data and the expected XML/HTML report, plus Surefire/Failsafe XML. If Maven never generated a file, changing Jenkins’ publisher will not fix the cause.
- Validate paths and plugin steps. Jenkins scans workspace-relative paths. Check case-sensitive patterns and module depth, then verify that the selected publisher plugin is installed and its step syntax matches the installed version. The Jenkins console log can reveal an unmatched report or unavailable step. Coverage Pipeline step
- Preserve the original build failure. The
post { always { ... } }block is preferable to suppressing Maven errors with|| true. If usingsh(returnStatus: true)to collect results after Maven exits nonzero, save the exit status and restore a failed build after publication; otherwise compilation or test failures can be hidden. - Check the lifecycle phase and tool compatibility.
verify-bound checks do not run when someone invokes onlymvn test. Confirm the agent’s Maven/JDK versions against the selected plugin documentation and check that Jenkins is running the intended Maven executable or wrapper.
For HTML line-level highlighting, JaCoCo requires compiled classes to include debug information. If tests stop before reports are flushed or the build is interrupted, there may be no files for Jenkins to publish. JaCoCo Maven plugin documentation
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

