Add JaCoCo coverage measurement and Codecov reporting - #1553
Merged
Conversation
The 'coverage' profile produced no data at all. maven-surefire-plugin's
pluginManagement set a literal <argLine> for the --add-opens flags, which
overrode the argLine property that jacoco:prepare-agent sets, so the agent
never attached to the forked test JVMs.
Surefire now consumes @{jacoco.argLine}, substituted at fork time. That
placeholder property must stay declared even though it is empty: surefire
only substitutes @{x} for properties that exist, and would otherwise hand
the literal token to the JVM and break every test module whenever the
profile is inactive.
Per-module reports would have been misleading too, because most tests live
in a module other than the code they exercise: wicket-core has no tests of
its own, and wicket-core-tests has no production classes. The new
wicket-coverage module aggregates the reactor with jacoco:report-aggregate
instead, using dependency scope to say what belongs in the report -- compile
contributes classes and sources, test contributes execution data only. The
per-module 'report' execution is dropped.
Coverage is measured on the JDK 21 leg of the existing build and uploaded to
Codecov for every push and pull request. It is reported, never enforced:
codecov.yml marks both status checks informational, so neither can fail a
build or block a merge.
check-coverage-report.py guards the measurement itself. Should a future
<argLine> override drop the placeholder, or a dependency scope change,
coverage would silently fall to zero rather than fail; the script asserts
the module set and non-zero coverage for the three cross-module cases, but
never a percentage.
Current aggregate: 67.5% of instructions, 67.4% of lines.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wicket had no coverage numbers and no way to see them. It turned out the measurement side was already half-present but broken in two independent ways, so this fixes both and then wires the result up to a UI.
Why
-Pcoverageproduced nothingThe agent never attached.
maven-surefire-plugin'spluginManagementset a literal<argLine>for the--add-opensflags.jacoco:prepare-agentworks by setting anargLineproperty, and an explicit<argLine>element wins over it, so the whole suite ran uninstrumented and nojacoco.execwas ever written.Surefire now consumes
@{jacoco.argLine}, substituted at fork time. The placeholder property has to stay declared even though it is empty: surefire only substitutes@{x}for properties that actually exist, and would otherwise hand the literal token to the JVM and break every test module whenever the profile is inactive. It is deliberately namedjacoco.argLinerather than the bareargLine, becauseargLineis also surefire's own parameter expression — a reactor-wide<argLine />property would pin surefire's fallback everywhere and turnmvn -DargLine=-Xmx4ginto a silent no-op.Per-module reports would have been misleading anyway. Most tests live in a module other than the code they exercise:
wicket-corehas 842 main classes and no tests, whilewicket-core-testshas ~500 test classes and no production code. Same split forwicket-cdi/wicket-cdi-tests. Per-module JaCoCo reportswicket-coreat 0%.So the per-module
reportexecution is dropped in favour of a newwicket-coveragemodule that aggregates the reactor withjacoco:report-aggregate. Its dependency list is the configuration —report-aggregatereads dependency scope, wherecompilecontributes classes and sources andtestcontributes execution data only. That one distinction is what letswicket-coreget credit for tests that live elsewhere.Two subtleties in that pom, both called out in comments:
wicket-testeris managed to<scope>test</scope>in the parent, and scope defaulting runs after management injection, so it needs an explicit<scope>compile</scope>or its classes silently vanish from the report.report-aggregatehas no default phase, and with no execution data it happily emits a well-formed 0%jacoco.xml. It is therefore gated on the samecoverageprofile that attaches the agent, so "the report exists" implies "the agent ran".Reporting
Coverage is measured on the JDK 21 leg of the existing build and uploaded to Codecov for every push and pull request. Riding on the existing build means the only marginal cost is load-time instrumentation on one leg, rather than a second full test run per commit on shared ASF runners. Running on both
pushandpull_requestis deliberate: Codecov needs coverage on the base commit to compute a meaningful diff.Coverage is reported, never enforced.
codecov.ymlmarks both status checksinformational, so they show real numbers on a PR but cannot fail a build or block a merge.require_changes: truekeeps the bot quiet on PRs that do not move coverage.On ASF policy:
codecov/codecov-actionis already blanket-approved on the allowlist inapache/infrastructure-actions, so no security review is needed, and it is pinned to a commit SHA as the policy requires. Fork PRs get no repository secrets and so upload tokenlessly, which Codecov supports for public upstreams — note the comment in the workflow warning against "fixing" that withpull_request_target.fail_ci_if_erroris left at its default offalseon purpose, so a Codecov outage cannot redden every push.The tripwire
If a future
<argLine>override forgets the placeholder, or a dependency scope changes, coverage falls silently to zero instead of failing — it would show up only as an unexplained cliff on the trend line..github/scripts/check-coverage-report.pyruns before the upload and asserts the expected module set plus non-zero coverage for the three cross-module cases. It deliberately checks structure, never a percentage: it is a correctness check on the measurement, not a quality gate.Results
mvn clean verify -Pcoverageon the full reactor, JDK 21:The two zeroes are legitimate:
wicket-jmxandwicket-native-websocket-javaxcontain onlyApacheLicenceHeaderTest, which reads license headers and never exercises its own module's classes. Their exec files do exist, so the agent attached.Verified locally:
-javaagent:and all five--add-*flags; with it off, the placeholder resolves to nothing and no exec file appears.wicket-core-tests— the ones that fail hard without--add-opens java.base/java.lang— pass with the profile off, which is what the JDK 25/26 legs will do.maven-enforcer-pluginpasses on the new module with nodependencyManagementpins needed;dependencyConvergenceexcludes test and provided scopes by default, which prunes thewicket-core-testssubtree entirely.codecov.ymlis accepted by Codecov's own validator.Not done here
There is no JIRA ticket for this yet — happy to file one and retitle if the PMC would prefer that. Left for follow-ups: the same treatment on
wicket-10.x(itscoverageprofile has the identical defect), ajacoco.versionbump from 0.8.15 to 0.8.16, and a README badge.Worth a note on dev@ either way, since this adds a third-party service to the CI surface and puts a bot comment on pull requests.
🤖 Generated with Claude Code