CI integration
The plugin needs two things in a pipeline: the full git history, so it can diff against the base branch, and the base ref to diff against.
GitHub Actions
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: ./gradlew affectedTest -PaffectedTestsBaseRef=${{ github.event.pull_request.base.sha }}
GitLab CI and Jenkins
./gradlew affectedTest -PaffectedTestsBaseRef=origin/main
Make sure the job checks out the full history (fetch-depth: 0 on GitHub, GIT_DEPTH: 0 on GitLab). A shallow clone that does not contain the base ref cannot be diffed, so the run fails before selection. That is deliberate: a pipeline should break loudly instead of silently skipping tests.
What changes in CI
With mode unset the plugin uses auto, which resolves to ci when any of these environment variables is set: CI, GITLAB_CI, GITHUB_ACTIONS, JENKINS_HOME, CIRCLECI, TRAVIS, BUILDKITE or TF_BUILD. Otherwise it resolves to local.
The difference is how it treats uncertainty. Locally, a run that finds no tests is skipped and a parse failure still runs the tests it found, because a developer wants fast iteration. In CI both escalate to the full suite, because a pipeline should never merge a change on a partial selection.
| Situation | local | ci | strict |
|---|---|---|---|
DISCOVERY_EMPTY | skipped | full suite | full suite |
DISCOVERY_INCOMPLETE | selected | full suite | full suite |
The decision model lists every default.
Properties you can pass on the command line
| Property | Effect |
|---|---|
-PaffectedTestsBaseRef=<ref> | The git ref to diff against. |
-PaffectedTestsMode=<mode> | auto, local, ci or strict. |
-PaffectedTestsParallelDiscovery=false | Run discovery serially. |
Coverage and quality gates
affectedTest runs each module's normal test task, so JaCoCo, jacocoTestReport, the org.sonarqube plugin and jacoco-report-aggregation attach unchanged. Coverage on the lines you changed reflects the tests the plugin selected, which is what new-code gates need. Overall coverage drops on a merge-request pipeline because untouched tests do not run, so point your gate at new code rather than the whole project.
Timeouts
gradlewTimeoutSeconds puts a wall-clock limit on the nested ./gradlew :module:test call. It defaults to 0, which waits forever. A positive value stops a hung test from holding a CI worker, and the build then fails. If you rely on Develocity build-scan capture of the nested output, leave it at 0 and enforce the deadline at the CI job level, because the timeout path uses inherited stdio.
For shallow clones, cache invalidation and performance tuning, see the troubleshooting guide.