Two things to know before any setup steps. First, SonarQube’s default quality gate does not gate your project’s overall coverage — all four of its conditions are on new code. Second, JaCoCo 0.8.4 cannot instrument modern Java bytecode, and when it fails it reports 0% coverage while your build still exits 0. That second one is measured below, not asserted.
Table of Contents
The default gate is about new code
SonarSource’s documentation on quality gates says:
“The Sonar way quality gate is Sonar’s recommended quality gate for your new code, helping you achieve high quality code. It is provided by Sonar, activated by default, and read-only.” … “This quality gate focuses on keeping high quality standards for new code, rather than spending a lot of effort remediating old code.” … “The Sonar way quality gate has four conditions: No new issues are introduced · All new Security Hotspots are reviewed · New code test coverage is greater than or equal to 80.0% · Duplication in the new code is less than or equal to 3.0%”
So the 80% figure is real, it is Sonar’s, and it applies to the lines you changed — not to the repository. Requiring at least 80% code coverage for a project to pass the Quality Gate is a harsher condition you have to build yourself, and on an existing codebase it fails on day one for reasons no pull request caused. An overall-code condition is available — the same doc says branches apply “Both the conditions defined on overall code and conditions defined on new code” — it is just not what you get by default.
JaCoCo 0.8.4 silently reports zero on Java 26
If pom.xml pins jacoco-maven-plugin to version 0.8.4 and you compile with a current JDK, that agent cannot read the class files. One class compiled by javac 26.0.2, the same run under seven JaCoCo releases:
$ xxd -l 8 classes/Calc.class
00000000: cafe babe 0000 0046 # major version 70 = Java 26
JaCoCo JVM exit instructions lines
0.8.4 0 0 / 17 0 / 4
0.8.7 0 0 / 17 0 / 4
0.8.11 0 0 / 17 0 / 4
0.8.12 0 0 / 17 0 / 4
0.8.13 0 0 / 17 0 / 4
0.8.14 0 16 / 17 4 / 4
0.8.15 0 16 / 17 4 / 4
The failing runs print java.lang.IllegalArgumentException: Unsupported class file major version 70 to stderr — once per class, buried in an instrumentation stack trace — and then the JVM exits 0 and the tests pass. Coverage arrives at SonarQube as zero: a gated build fails for a reason unrelated to your tests, and an ungated one quietly reports a lie. That is the duty-of-care point here — a stale JaCoCo does not break the build, it corrupts the metric the gate is built on.
The cutover matches JaCoCo’s changelog: release 0.8.14 (2025/10/11) lists “Experimental support for Java 26 class files” and release 0.8.15 (2026/06/04) lists “JaCoCo now officially supports Java 26” — and 0.8.14 is where the numbers above stop being zero. SonarSource’s Java coverage page still showed <version>0.8.7</version> in its example pom.xml in August 2026, which is in the failing half of that table. Pin the current JaCoCo, not the one in any example.
The table above comes from compiling with Java 26, and sonarqube-jacoco-code-coverage-gate.sh asserts its numbers only on a Java 26 JDK: it downloads the seven JaCoCo releases from Maven Central (about 29 MB), repeats the zero-assertion test below, re-fetches the SonarSource and JaCoCo sentences quoted here, and reports SKIP for any step that needs a JDK or network it does not find.
100% line coverage, zero assertions, one bug
The other habit worth breaking is reading a coverage percentage as test quality. JaCoCo counts instructions that executed; it has no idea whether anything was checked. The whole class:
public class Calc {
public int divide(int a, int b) {
if (b == 0) { return 0; } // wrong, and covered
return a / b;
}
public String label(int n) {
return n > 0 ? "positive" : "not positive";
}
}
and the whole “test”, which asserts nothing:
Calc c = new Calc();
c.divide(10, 2);
c.divide(1, 0);
c.label(5);
JaCoCo 0.8.15 reports, from the CSV output:
LINE_MISSED 0 LINE_COVERED 4 -> 100% line coverage
METHOD_MISSED 0 METHOD_COVERED 3 -> 100% method coverage
BRANCH_MISSED 1 BRANCH_COVERED 3 -> 75% branch coverage
100% of lines, and divide(1, 0) returns 0 instead of throwing — a bug, fully covered, with no test that would ever notice. Meanwhile label packs two branches onto one line, so calling it once gives that line full line coverage and half its branch coverage. The gap between 100% and 75% is the difference between “the code ran” and “the code was exercised”, and only one of those numbers is in SonarQube’s default gate. Those counts are for the class exactly as printed; put the if body on its own line and the same run reports 5 of 5 lines instead of 4 of 4 — its own small lesson about what a line-coverage percentage measures.
Reproduce it in four commands, no Maven required:
javac -d classes src/Calc.java src/CalcTest.java
java -javaagent:lib/jacocoagent.jar=destfile=j.exec -cp classes CalcTest
java -jar lib/jacococli.jar report j.exec \
--classfiles classes/Calc.class --csv out.csv
cat out.csv
Wiring it to SonarQube
Cited, not run. SonarSource’s Java test coverage page gives the ordering rule — “Adjust your build process so that JaCoCo report generation step runs before the SonarScanner step” — and a default that removes a configuration step: “By default, the generated report will be saved under target/site/jacoco/jacoco.xml. This location will be checked automatically by the scanner, so no further configuration is required.” Setting sonar.coverage.jacoco.xmlReportPaths to that exact default path is redundant; the property is for reports written elsewhere, such as a multi-module aggregate. To read gate status from CI rather than the dashboard, see the SonarQube Web API guide.
Not verified here: anything needing a SonarQube server, SonarScanner, Maven, Gradle or JUnit — none exist on the machine this was measured on, so every SonarQube sentence above is a quotation. The coverage numbers came from the JaCoCo agent driven by a main() method, the same instrumentation path a JUnit run uses but not a Maven build. No SonarQube UI screenshots are included, because none were taken on a running instance.