Package io.affectedtests.gradle
Class AffectedTestTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
io.affectedtests.gradle.AffectedTestTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
public abstract class AffectedTestTask
extends org.gradle.api.DefaultTask
Gradle task that detects affected tests and executes them.
Execution flow:
- Detects git changes against the configured base ref
- Maps changed files to production/test classes
- Discovers which test classes are affected
- Groups FQNs by owning subproject and runs
:<module>:test --tests <fqn>once per module so that--testsfilters don't cross module boundaries
Not compatible with Configuration Cache: reads live git state and scans the file system at execution time. The task is also deliberately marked as never up-to-date so git changes always trigger a re-run.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
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> Glob patterns for files to exclude from analysis.protected abstract org.gradle.process.ExecOperationsInjected by Gradle for executing the test subprocess.abstract org.gradle.api.provider.ListProperty<String> Suffixes for finding implementation classes (e.g.abstract org.gradle.api.provider.Property<Boolean> Whether to include tests for implementations of changed interfaces/base classes.abstract org.gradle.api.provider.Property<Boolean> Whether to include staged (added to index) changes in the diff.abstract org.gradle.api.provider.Property<Boolean> Whether to include uncommitted (unstaged) changes in the diff.abstract org.gradle.api.file.DirectoryPropertyThe root project directory (resolved at configuration time).abstract org.gradle.api.provider.Property<Boolean> Whether to run the full test suite when no affected tests are found.abstract org.gradle.api.provider.ListProperty<String> Production source directories relative to each module root.abstract org.gradle.api.provider.ListProperty<String> Discovery strategies to use for finding affected tests.Map of subproject directory (relative to the root project, empty string for the root project itself) to the Gradle path of that subproject (e.g.abstract org.gradle.api.provider.ListProperty<String> Test source directories relative to each module root.abstract org.gradle.api.provider.ListProperty<String> Suffixes used by the naming strategy to find test classes.abstract org.gradle.api.provider.Property<Integer> How many levels of transitive dependencies to follow when thetransitivestrategy is enabled.voidDetects affected tests and executes them via a Gradle subprocess.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
AffectedTestTask
public AffectedTestTask()
-
-
Method Details
-
getBaseRef
Git base ref to diff against. Default:"origin/master". Override via-PaffectedTestsBaseRef=....- Returns:
- the base ref property
-
getIncludeUncommitted
Whether to include uncommitted (unstaged) changes in the diff. Default:true.- Returns:
- the include uncommitted property
-
getIncludeStaged
Whether to include staged (added to index) changes in the diff. Default:true.- Returns:
- the include staged property
-
getRunAllIfNoMatches
Whether to run the full test suite when no affected tests are found. Default:false(skip tests when nothing is affected).- Returns:
- the run-all-if-no-matches property
-
getStrategies
Discovery strategies to use for finding affected tests. Valid values:"naming","usage","impl","transitive". Default: all four.- Returns:
- the strategies list property
-
getTransitiveDepth
How many levels of transitive dependencies to follow when thetransitivestrategy is enabled. Range: 0 (disabled) to 5. Default:2.- Returns:
- the transitive depth property
-
getTestSuffixes
Suffixes used by the naming strategy to find test classes. 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
Glob patterns for files to exclude from analysis. Default:["**/generated/**"].- Returns:
- the exclude paths list property
-
getIncludeImplementationTests
Whether to include tests for implementations of changed interfaces/base classes. Default:true.- Returns:
- the include implementation tests property
-
getImplementationNaming
Suffixes for finding implementation classes (e.g."Impl"matchesFooServiceImplfor a changedFooService). Default:["Impl"].- Returns:
- the implementation naming list property
-
getSubprojectPaths
Map of subproject directory (relative to the root project, empty string for the root project itself) to the Gradle path of that subproject (e.g.":services:payment"). Populated automatically by the plugin and used to group affected test FQNs by their owning module.- Returns:
- the subproject dirs map property
-
getRootDir
@Internal public abstract org.gradle.api.file.DirectoryProperty getRootDir()The root project directory (resolved at configuration time).- Returns:
- the root dir property
-
getExecOperations
@Inject protected abstract org.gradle.process.ExecOperations getExecOperations()Injected by Gradle for executing the test subprocess.- Returns:
- the exec operations service
-
runAffectedTests
public void runAffectedTests()Detects affected tests and executes them via a Gradle subprocess.
-