Skip to content

Restrict JaCoCo instrumentation to Spock packages#2374

Merged
leonard84 merged 1 commit into
spockframework:masterfrom
leonard84:configure-jacoco-includes
Jun 13, 2026
Merged

Restrict JaCoCo instrumentation to Spock packages#2374
leonard84 merged 1 commit into
spockframework:masterfrom
leonard84:configure-jacoco-includes

Conversation

@leonard84

Copy link
Copy Markdown
Member

What

Configure JaCoCo to only instrument Spock's own packages (spock.* and org.spockframework.*) instead of instrumenting every class loaded under test.

Why

The JaCoCo agent was instrumenting all loaded classes, including the third-party libraries exercised by the specs. Restricting instrumentation to Spock's packages keeps coverage data focused on the code we actually own and reduces instrumentation overhead.

Changes

  • SpockBasePlugin: the jacoco Gradle plugin's JacocoTaskExtension had no include filter, so every Test task instrumented everything. Set includes = ['spock.*', 'org.spockframework.*'] on all Test tasks.
  • JacocoJavaagentProvider: the custom agent used for the compileTestGroovy AST-dump coverage already filtered to org.spockframework.*; added the missing spock.* (the agent's includes option is colon-separated).

Configure both the JaCoCo Gradle plugin's Test task agent and the
custom compile-time agent to only instrument spock.* and
org.spockframework.* classes, rather than instrumenting all classes
loaded under test.
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8413573-65e0-4329-bb2c-5a420ef28edf

📥 Commits

Reviewing files that changed from the base of the PR and between 963a05c and fd4fd4c.

📒 Files selected for processing (2)
  • build-logic/base/src/main/groovy/org/spockframework/gradle/JacocoJavaagentProvider.groovy
  • build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy

📝 Walkthrough

Walkthrough

JaCoCo instrumentation is expanded to cover both spock.* and org.spockframework.* packages. SpockBasePlugin adds an import for JacocoTaskExtension and configures Test tasks with an includes filter. JacocoJavaagentProvider updates the javaagent argument to match the same package scope.

Changes

JaCoCo Instrumentation Scope

Layer / File(s) Summary
JaCoCo test task configuration
build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy
Import JacocoTaskExtension and configure all Test tasks to restrict instrumentation to spock.* and org.spockframework.* packages.
JaCoCo javaagent filter update
build-logic/base/src/main/groovy/org/spockframework/gradle/JacocoJavaagentProvider.groovy
Expand the -javaagent argument's includes filter to cover both org.spockframework.* and spock.* packages.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through coverage logs,
Two package paths now shine so bright—
spock. and org.spockframework together,*
Instrumenting all through the night!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main objective of the PR: restricting JaCoCo instrumentation to Spock packages.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about what is being changed, why, and how the changes work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leonard84 leonard84 self-assigned this Jun 13, 2026
@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown

Greptile Summary

This PR restricts JaCoCo instrumentation to Spock's own class packages (spock.* and org.spockframework.*) in both the Gradle plugin JacocoTaskExtension path and the custom JVM agent path used during compileTestGroovy, preventing third-party library classes from inflating coverage data.

  • SpockBasePlugin: registers a configureEach action on all Test tasks to set JacocoTaskExtension.includes; the JaCoCo Gradle plugin is applied before this block runs, so getByType(JacocoTaskExtension) is always safe.
  • JacocoJavaagentProvider: appends :spock.* to the pre-existing includes=org.spockframework.* agent string, making both instrumentation paths consistent.

Confidence Score: 5/5

Both changes are narrow build-logic adjustments with no impact on production or test runtime behavior, only on which classes JaCoCo instruments.

The two changed files are isolated to build configuration. The JaCoCo Gradle plugin is always applied before the new configureEach block executes, so getByType(JacocoTaskExtension) will never throw. The wildcard patterns correctly cover all multi-level subpackages because JaCoCo's * wildcard matches across . separators, consistent with the pre-existing org.spockframework.* usage. The agent string and Gradle extension are now consistent with each other. No logic paths are affected.

No files require special attention.

Important Files Changed

Filename Overview
build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy Adds JacocoTaskExtension.includes filter to all Test tasks, restricting instrumentation to 'spock.' and 'org.spockframework.'. Import added; implementation is correct and safe given the JaCoCo plugin is always applied before this configureEach block runs.
build-logic/base/src/main/groovy/org/spockframework/gradle/JacocoJavaagentProvider.groovy Appends ':spock.' to the existing 'includes=org.spockframework.' agent argument, aligning the AST-dump coverage path with the new Gradle-task-level filter.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SpockBasePlugin.apply] --> B[applyPlugins\nApplies 'jacoco' Gradle plugin]
    B --> C[compileTasks]
    C --> D[jarTasks]
    D --> E[testTasks\nwithType Test .configureEach\nreports, timeout, SpockConfig]
    E --> F[jacoco\nSets toolVersion\nwithType Test .configureEach]
    F --> G{JacocoTaskExtension\nalready registered\nby Gradle JaCoCo plugin?}
    G -- Yes --> H[Set includes =\n'spock.*','org.spockframework.*']
    G -- No --> I[RuntimeException]

    J[compileTestGroovy task] --> K[JacocoJavaagentProvider.asArguments]
    K --> L['-javaagent:...includes=\norg.spockframework.*:spock.*']
Loading

Reviews (1): Last reviewed commit: "Restrict JaCoCo instrumentation to Spock..." | Re-trigger Greptile

@testlens-app

testlens-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: fd4fd4c
▶️ Tests: 99135 executed
⚪️ Checks: 33/33 completed


Learn more about TestLens at testlens.app.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.33%. Comparing base (963a05c) to head (fd4fd4c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2374   +/-   ##
=========================================
  Coverage     82.33%   82.33%           
  Complexity     4877     4877           
=========================================
  Files           474      474           
  Lines         15205    15205           
  Branches       1935     1935           
=========================================
  Hits          12519    12519           
  Misses         1993     1993           
  Partials        693      693           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leonard84 leonard84 merged commit b2699ee into spockframework:master Jun 13, 2026
38 checks passed
@leonard84 leonard84 deleted the configure-jacoco-includes branch June 13, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant