Class AffectedTestsExtension
Usage in build.gradle:
affectedTests {
baseRef = "origin/master"
// Defaults are COMMITTED-ONLY (both flags default to false) so
// local runs match CI. Flip to true if you want WIP to seed the
// diff while iterating on tests locally.
includeUncommitted = false
includeStaged = false
// v2: per-situation actions. See README.md for the full table.
mode = "ci"
onEmptyDiff = "full_suite"
onAllFilesOutOfScope = "skipped"
onUnmappedFile = "full_suite"
onDiscoveryEmpty = "full_suite"
ignorePaths = ["**/generated/**"]
outOfScopeTestDirs = ["api-test/src/test/java"]
strategies = ["naming", "usage", "impl", "transitive"]
transitiveDepth = 4
parallelDiscovery = true
testSuffixes = ["Test", "IT", "ITTest", "IntegrationTest"]
sourceDirs = ["src/main/java"]
testDirs = ["src/test/java"]
includeImplementationTests = true
implementationNaming = ["Impl", "Default"]
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract org.gradle.api.provider.Property<String> Git base ref to diff against.abstract org.gradle.api.provider.Property<Long> Wall-clock timeout in seconds for the nested./gradlewinvocation that executes the affected / full test suite.abstract org.gradle.api.provider.ListProperty<String> Glob patterns for files that must never influence test selection — for purely documentation, build metadata, or generated artifacts.abstract org.gradle.api.provider.ListProperty<String> Implementation naming prefixes/suffixes (e.g.abstract org.gradle.api.provider.Property<Boolean> Include tests for implementations of changed interfaces/base classes.abstract org.gradle.api.provider.Property<Boolean> Include staged changes.abstract org.gradle.api.provider.Property<Boolean> Include uncommitted (unstaged) changes.abstract org.gradle.api.provider.Property<Boolean> Whether to register the Kotlin AST-driven parser for.ktfiles (issue #76 Phase 2, PR #4).abstract org.gradle.api.provider.Property<String> getMode()Execution profile ("auto","local","ci", or"strict").abstract org.gradle.api.provider.Property<String> Action to take when every file in the diff matchedgetIgnorePaths().abstract org.gradle.api.provider.Property<String> Action to take when every file in the diff sat undergetOutOfScopeTestDirs()orgetOutOfScopeSourceDirs().abstract org.gradle.api.provider.Property<String> Action to take when discovery completes but returns no tests.abstract org.gradle.api.provider.Property<String> Action to take when discovery ran but at least one scanned Java file failed to parse — seeSituation.DISCOVERY_INCOMPLETEon the core module for the full rationale.abstract org.gradle.api.provider.Property<String> Action to take on an empty git diff.abstract org.gradle.api.provider.Property<String> Action to take when the diff contains at least one unmapped file (non-Java, outside configured source/test dirs).abstract org.gradle.api.provider.ListProperty<String> Production source directories the plugin must treat as out-of-scope.abstract org.gradle.api.provider.ListProperty<String> Test source directories (e.g.abstract org.gradle.api.provider.Property<Boolean> Whether to fan the four discovery strategies out across a small thread pool (defaulttrue) or run them serially.abstract org.gradle.api.provider.ListProperty<String> Production source directories (relative to each module root).abstract org.gradle.api.provider.ListProperty<String> Strategies to use for test discovery.abstract org.gradle.api.provider.ListProperty<String> Test source directories (relative to each module root).abstract org.gradle.api.provider.ListProperty<String> Test class suffixes used by the naming strategy.abstract org.gradle.api.provider.ListProperty<String> Names of the Gradle test tasks the dispatch path may invoke (one nested./gradlewcall permodule × taskNamepair).abstract org.gradle.api.provider.Property<Integer> How many levels of transitive dependencies to follow when thetransitivestrategy is enabled.voidsetExcludePaths(List<?> ignored) Migration shim:excludePathswas removed in v2.0.voidsetRunAllIfNoMatches(Object ignored) Migration shim:runAllIfNoMatcheswas removed in v2.0.voidsetRunAllOnNonJavaChange(Object ignored) Migration shim:runAllOnNonJavaChangewas removed in v2.0.
-
Constructor Details
-
AffectedTestsExtension
public AffectedTestsExtension()
-
-
Method Details
-
getBaseRef
Git base ref to diff against. Default:"origin/master".- Returns:
- the base ref property
-
getIncludeUncommitted
Include uncommitted (unstaged) changes. Default:false— committed-only semantics match CI. Set totrueif you iterate on WIP locally and want the unstaged edits to seed the diff boundary.- Returns:
- the include uncommitted property
-
getIncludeStaged
Include staged changes. Default:false. SeegetIncludeUncommitted()for the rationale.- Returns:
- the include staged property
-
getStrategies
Strategies to use for test discovery. Valid values:"naming","usage","impl","transitive". Default: all four.The
transitivestrategy additionally respectstransitiveDepth.- Returns:
- the strategies list property
-
getTransitiveDepth
How many levels of transitive dependencies to follow when thetransitivestrategy is enabled. Default:4— matches the depth most Java controller → service → repository chains actually reach in Modulr-shaped codebases while leaving one level of margin. Range: 0–5.- Returns:
- the transitive depth property
-
getParallelDiscovery
Whether to fan the four discovery strategies out across a small thread pool (defaulttrue) or run them serially. Engine- level parallelism is the Stage 1 win for issue #42; on the workloads we've measured it cuts discovery wall time by ~2x with no algorithmic change. Adopters can flip tofalseif a custom strategy fork or a JavaParser regression we have not seen yet introduces a race; the serial path remains a one-line fallback.The Gradle property
-PaffectedTestsParallelDiscovery=falseprovides the same kill switch without touching the DSL. The property acceptstrue|false|1|0|on|off|yes|no(case-insensitive); typo'd values are rejected with a build-log WARN rather than silently flipping the switch.- Returns:
- the parallel-discovery property
-
getKotlinEnabled
Whether to register the Kotlin AST-driven parser for.ktfiles (issue #76 Phase 2, PR #4). Defaults totrue— Kotlin sources participate in AST-driven discovery (Usage / Implementation / Transitive) on every run.When
true,KotlinLanguageParseris registered with the per-engineLanguageParsersregistry; AST-driven strategies start producing matches for Kotlin files; embeddable bootstrap failures fail closed viaDISCOVERY_INCOMPLETE(the WARN is logged once and every.ktin the run is treated as unparseable).When
false,.ktfiles fall back to the Phase 1 (PR #1) shape: path-derived FQN routing on the diff side, no AST-driven strategy participation, noDISCOVERY_INCOMPLETEon unparsed Kotlin — the absence is "by design" rather than a parse failure. Use this kill switch only as a regression escape hatch; PR #4 removed the-Daffected-tests.kotlin.enabledsystem property because the rollout window closed and the AST path is now first-class.- Returns:
- the Kotlin-enabled property
-
getTestSuffixes
Test class suffixes used by the naming strategy. Default:["Test", "IT", "ITTest", "IntegrationTest"].- Returns:
- the test suffixes list property
-
getSourceDirs
Production source directories (relative to each module root). Default:["src/main/java"].- Returns:
- the source dirs list property
-
getTestDirs
Test source directories (relative to each module root). Default:["src/test/java"].- Returns:
- the test dirs list property
-
getTestTaskNames
Names of the Gradle test tasks the dispatch path may invoke (one nested./gradlewcall permodule × taskNamepair). Default:["test"].Adopters with extra source sets opt them in here:
testTaskNames = ["test", "integrationTest"]. The dispatch path routes each discovered FQN to the task whose source-set directory the FQN's file sits under, by the standard Gradle conventionsrc/<taskName>/java. When setting this knob, callers typically also extendgetTestDirs()to include the corresponding source-set directories so the discovery passes scan them — otherwise the extra source sets stay invisible to discovery and the new task name has nothing to dispatch.- Returns:
- the test task names list property
-
getIgnorePaths
Glob patterns for files that must never influence test selection — for purely documentation, build metadata, or generated artifacts. A diff consisting entirely of ignored paths routes throughSituation.ALL_FILES_IGNORED.When unset, the core
AffectedTestsConfigdefault list applies (markdown, generated/, text/licence/changelog, images).- Returns:
- the ignore paths list property
-
getOutOfScopeTestDirs
Test source directories (e.g."api-test/src/test/java") whose contents the plugin must not dispatch via theaffectedTesttask. A diff entirely under these directories routes throughSituation.ALL_FILES_OUT_OF_SCOPE. Intended for Cucumber/api-test, performance, or other non-unit-test source sets.- Returns:
- the out-of-scope test dirs list property
-
getOutOfScopeSourceDirs
Production source directories the plugin must treat as out-of-scope. A diff entirely under these dirs routes throughSituation.ALL_FILES_OUT_OF_SCOPE.- Returns:
- the out-of-scope source dirs list property
-
getIncludeImplementationTests
Include tests for implementations of changed interfaces/base classes. Default:true.- Returns:
- the include implementation tests property
-
getImplementationNaming
Implementation naming prefixes/suffixes (e.g. "Impl" matchesFooBarImplforFooBar; "Default" matchesDefaultFooBarforFooBar). Default:["Impl", "Default"].- Returns:
- the implementation naming list property
-
getMode
Execution profile ("auto","local","ci", or"strict"). Controls per-situation default actions when the explicitonXxxsetting is not set.Default: unset — which resolves to
Mode.AUTOon the core config.AUTOdetects CI via common env vars and picks the CI defaults there, and the LOCAL defaults otherwise.- Returns:
- the mode property
-
getOnEmptyDiff
Action to take on an empty git diff. One of"selected","full_suite","skipped"(case-insensitive).- Returns:
- the on-empty-diff property
-
getOnAllFilesIgnored
Action to take when every file in the diff matchedgetIgnorePaths(). One of"selected","full_suite","skipped".- Returns:
- the on-all-files-ignored property
-
getOnAllFilesOutOfScope
Action to take when every file in the diff sat undergetOutOfScopeTestDirs()orgetOutOfScopeSourceDirs(). One of"selected","full_suite","skipped".- Returns:
- the on-all-files-out-of-scope property
-
getOnUnmappedFile
Action to take when the diff contains at least one unmapped file (non-Java, outside configured source/test dirs). One of"selected","full_suite","skipped". When set to"selected"the engine treats the unmapped file as if it weren't there and continues to discovery — matching pre-v2runAllOnNonJavaChange=falsebehaviour.- Returns:
- the on-unmapped-file property
-
getOnDiscoveryEmpty
Action to take when discovery completes but returns no tests. One of"selected","full_suite","skipped".- Returns:
- the on-discovery-empty property
-
getOnDiscoveryIncomplete
Action to take when discovery ran but at least one scanned Java file failed to parse — seeSituation.DISCOVERY_INCOMPLETEon the core module for the full rationale. One of"selected","full_suite","skipped".Unset falls through to the
modedefault (CI and STRICT escalate tofull_suite; LOCAL keeps the partial selection).- Returns:
- the on-discovery-incomplete property
-
getGradlewTimeoutSeconds
Wall-clock timeout in seconds for the nested./gradlewinvocation that executes the affected / full test suite.0disables the timeout (pre-v1.9.22 default — wait indefinitely). Positive values deadline the child process: the plugin destroys the process tree after the interval and fails the build with a clear error.Recommended values:
1800(30 min) for merge-gate unit-test runs,3600(1 hour) for suites that include integration tests. Must be>= 0; the plugin rejects negative values atafterEvaluate(configuration) time and again at task-execution time as belt-and-braces.- Returns:
- the gradlew timeout property in seconds
-
setRunAllIfNoMatches
Migration shim:runAllIfNoMatcheswas removed in v2.0. Intercepts a v1-style assignment in Groovy DSL and raises a targeted migration error instead of Gradle's generic "unknown property" failure.- Parameters:
ignored- v1 boolean value (never read)- Throws:
org.gradle.api.GradleException- always, with a v2 replacement hint
-
setRunAllOnNonJavaChange
Migration shim:runAllOnNonJavaChangewas removed in v2.0.- Parameters:
ignored- v1 boolean value (never read)- Throws:
org.gradle.api.GradleException- always, with a v2 replacement hint
-
setExcludePaths
Migration shim:excludePathswas removed in v2.0.- Parameters:
ignored- v1 list value (never read)- Throws:
org.gradle.api.GradleException- always, with a v2 replacement hint
-