Affected Tests Docs

Configuration

Every setting has a default. Override only what you need, in the affectedTests block of the build.gradle that applies the plugin:

affectedTests {
    baseRef = "origin/main"
    outOfScopeTestDirs = ["e2e-tests/**"]
    onConfigurationClassChanged = "integration_tests"
}

In the Kotlin DSL, assign with .set(...), for example baseRef.set("origin/main") and outOfScopeTestDirs.set(listOf("e2e-tests/**")).

You can see each of these settings change a real selection in the playground.

Diff

SettingDefaultWhat it does
baseRef"origin/master"The git ref to diff against. Also settable with -PaffectedTestsBaseRef=<ref>. If it cannot be resolved the build fails, so a CI run never silently skips tests.
includeUncommittedfalseAdd uncommitted changes to the diff. The default is committed-only, so a local run matches the diff CI will see on the same HEAD and gives the same selection however your working tree looks. Turn it on locally while iterating; leave it off in CI.
includeStagedfalseAdd staged changes to the diff. Same guidance as includeUncommitted.

Mode and per-situation actions

SettingDefaultWhat it does
modeunset, which means "auto""auto", "local", "ci" or "strict". Seeds the default action for every situation. Also settable with -PaffectedTestsMode=<mode>. See mode profiles.
onEmptyDifffrom modeAction when the diff is empty.
onAllFilesIgnoredfrom modeAction when every file matched ignorePaths.
onAllFilesOutOfScopefrom modeAction when every file is out of scope.
onUnmappedFile"full_suite" in every modeAction when the diff holds a file that does not map to a Java class. This is the safety knob for merge requests. Set "selected" to treat such files as absent and continue to discovery.
onDiscoveryEmptyfrom modeAction when discovery finds no tests.
onDiscoveryIncompletefrom modeAction when a scanned file failed to parse.

Each onXxx setting takes "selected", "full_suite" or "skipped". An explicit value always beats the mode default.

Path buckets

SettingDefaultWhat it does
ignorePaths**/generated/**, *.md, *.txt, LICENSE, LICENSE.*, CHANGELOG* and *.png, *.jpg, *.jpeg, *.svg, *.gif (each also as **/… for nested paths)Files that must not influence selection. A diff made only of these is ALL_FILES_IGNORED. Setting this replaces the defaults, so copy the ones you still want.
outOfScopeTestDirs[]Test source sets that affectedTest never dispatches, such as Cucumber or Gatling modules. A diff entirely under them is ALL_FILES_OUT_OF_SCOPE.
outOfScopeSourceDirs[]Production source sets to treat as out of scope. Same pattern shapes as above.

outOfScopeTestDirs and outOfScopeSourceDirs accept two kinds of entry, and you can mix them:

  • Literal directory prefixes. "api-test/src/test/java" matches that path at the repository root or under any module, such as services/orders/api-test/src/test/java/.... "api-test" never claims a sibling like api-test-utils/....
  • Ant-style globs. "api-test/**" or "**/api-test/**", using the standard JVM glob syntax (*, **, ?, [abc], {a,b}).

If you set one of these but --explain prints a Hint: saying no file matched, your pattern does not bite. Check it: a valid-looking glob that matches nothing is easy to write and would otherwise show up only after a full-suite CI run.

Discovery

SettingDefaultWhat it does
strategies["naming", "usage", "impl", "transitive", "headerEdges"]The strategies to run. See how it works.
transitiveDepth4How many levels the transitive strategy walks. Clamped to 0 to 5; 0 turns the strategy off.
testSuffixes["Test", "IT", "ITTest", "IntegrationTest"]Suffixes the naming strategy tries for a class.
includeImplementationTeststrueAlso select tests for implementations of a changed interface.
implementationNaming["Impl", "Default"]Prefixes and suffixes that mark an implementation: Impl matches FooImpl for Foo, Default matches DefaultFoo.
parallelDiscoverytrueRun the strategies on a small thread pool. Also settable with -PaffectedTestsParallelDiscovery=false.
kotlinEnabledtrueParse .kt files. Set false to fall back to path-based mapping for Kotlin.

Source and test directories

SettingDefaultWhat it does
sourceDirsRead from the Java plugin's source sets, falling back to ["src/main/java"]Production directories. An explicit list always wins over auto-discovery.
testDirsRead from the Java plugin's source sets, falling back to ["src/test/java"]Test directories. Any source set with a Test task is included, including custom names like integrationTest.
testTaskNames["test"]Gradle test tasks the dispatcher may call. If you add integrationTest, make sure its directory is in testDirs so discovery can see those tests.

Header edges

These tune the headerEdges strategy. See how it works for what it does.

SettingDefaultWhat it does
headerEdgesEnabledtrueKill switch for the strategy.
headerEdgesExclude[]Categories to turn off: "extends", "implements", "permits", "type-bounds", "record-components", "annotations". Turning off "annotations" is the usual choice for code with many custom class-level annotations that carry no test-relevant behaviour.
headerEdgesDepth1How many hops to follow. Clamped to 0 to 2; higher values approach a full suite on real code, and 0 is the kill switch.
headerEdgesMaxSiblings5When a header-added type has more than this many direct subtypes, the downward walk from it is suppressed. This stops a base class with 52 subclasses from selecting every controller test. 0 suppresses every such walk.
headerEdgesIgnoreJDK (java.lang, java.util, java.io, java.time, java.math, java.nio, java.text), javax, jakarta, Spring, JUnit, Mockito, Lombok, Kotlin and groovy.lang globsFully qualified name globs whose header edges are muted. Setting this replaces the defaults, so concatenate with them if you only want to add one.

Spring escalation

These settings decide what a changed Spring class adds to the selection. Spring and @Bean changes explains the reasoning.

SettingDefaultWhat it does
onApplicationClassChanged"full_suite"Effect when a changed class carries an application annotation. "full_suite", "integration_tests" or "off".
onConfigurationClassChanged"full_suite"Effect when a changed class carries a configuration annotation. Same values.
applicationAnnotations["SpringBootApplication"]Annotations that mark an application entry point, matched by simple name.
configurationAnnotations["Configuration", "SpringBootConfiguration", "ConfigurationProperties"]Annotations that mark a configuration class, matched by simple name.
integrationTestPatterns["**/*IT", "**/*ITTest", "**/*IntegrationTest"]Globs over the test class name, with dots read as /, that define an integration test.

Execution

SettingDefaultWhat it does
gradlewTimeoutSeconds0 (no timeout)Wall-clock limit for the nested ./gradlew :module:test call. On timeout it terminates the child and fails the build. A negative value is rejected at configuration time, so a typo is caught by ./gradlew help.

A fuller example

affectedTests {
    baseRef = "origin/main"
    mode = "auto"

    outOfScopeTestDirs = ["e2e-tests/**", "performance-test/**"]

    onUnmappedFile = "full_suite"
    onDiscoveryEmpty = "full_suite"
    onDiscoveryIncomplete = "full_suite"

    onApplicationClassChanged = "full_suite"
    onConfigurationClassChanged = "integration_tests"

    transitiveDepth = 4
    testTaskNames = ["test", "integrationTest"]
    testDirs = ["src/test/java", "src/integrationTest/java"]

    gradlewTimeoutSeconds = 3600
}