Package io.affectedtests.gradle
Class AffectedTestsExtension
java.lang.Object
io.affectedtests.gradle.AffectedTestsExtension
DSL extension for configuring the Affected Tests plugin.
Usage in build.gradle:
affectedTests {
baseRef = "origin/master"
includeUncommitted = true
// v2: per-situation actions (replaces runAllIfNoMatches / runAllOnNonJavaChange).
// See README.md "Migrating from v1 config" 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
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.ListProperty<String> Deprecated.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<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 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> Run full test suite if no affected tests are found.abstract org.gradle.api.provider.Property<Boolean> Force a full test run whenever the change set contains any file that cannot be resolved to a Java class undergetSourceDirs()orgetTestDirs()— for exampleapplication.yml,build.gradle, a Liquibase changelog, or a logback config.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.Property<Integer> How many levels of transitive dependencies to follow when thetransitivestrategy is enabled.
-
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:true.- Returns:
- the include uncommitted property
-
getIncludeStaged
Include staged changes. Default:true.- Returns:
- the include staged property
-
getRunAllIfNoMatches
Run full test suite if no affected tests are found. Default:false.- Returns:
- the run-all-if-no-matches property
-
getRunAllOnNonJavaChange
Force a full test run whenever the change set contains any file that cannot be resolved to a Java class undergetSourceDirs()orgetTestDirs()— for exampleapplication.yml,build.gradle, a Liquibase changelog, or a logback config. Files matchinggetExcludePaths()are treated as an explicit opt-out and do not trigger the escalation.Default:
true— "run more, never run less".- Returns:
- the run-all-on-non-java-change 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:2. Range: 0–5.- Returns:
- the transitive depth 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
-
getExcludePaths
Deprecated.prefergetIgnorePaths()in new configs.Glob patterns for files to exclude from analysis. v2 back-compat alias forgetIgnorePaths(). Default is an empty Gradle property — when unset, the v2ignorePathsdefault applies (a broader list than the pre-v2 single-entry["**/generated/**"]list).- Returns:
- the exclude paths 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 neither the explicitonXxxsetting nor the legacy boolean translation has picked one.Default: unset — which preserves the pre-v2 defaults for zero-config users. Setting it to
"auto"is the recommended migration: it detects 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
-
getIgnorePaths()in new configs.