Class AffectedTestsExtension

java.lang.Object
io.affectedtests.gradle.AffectedTestsExtension

public abstract class AffectedTestsExtension extends Object
DSL extension for configuring the Affected Tests plugin.

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
     testSuffixes = ["Test", "IT", "ITTest", "IntegrationTest"]
     sourceDirs = ["src/main/java"]
     testDirs = ["src/test/java"]
     includeImplementationTests = true
     implementationNaming = ["Impl", "Default"]
 }
 
  • Constructor Details

    • AffectedTestsExtension

      public AffectedTestsExtension()
  • Method Details

    • getBaseRef

      public abstract org.gradle.api.provider.Property<String> getBaseRef()
      Git base ref to diff against. Default: "origin/master".
      Returns:
      the base ref property
    • getIncludeUncommitted

      public abstract org.gradle.api.provider.Property<Boolean> getIncludeUncommitted()
      Include uncommitted (unstaged) changes. Default: false — committed-only semantics match CI. Set to true if you iterate on WIP locally and want the unstaged edits to seed the diff boundary.
      Returns:
      the include uncommitted property
    • getIncludeStaged

      public abstract org.gradle.api.provider.Property<Boolean> getIncludeStaged()
      Include staged changes. Default: false. See getIncludeUncommitted() for the rationale.
      Returns:
      the include staged property
    • getStrategies

      public abstract org.gradle.api.provider.ListProperty<String> getStrategies()
      Strategies to use for test discovery. Valid values: "naming", "usage", "impl", "transitive". Default: all four.

      The transitive strategy additionally respects transitiveDepth.

      Returns:
      the strategies list property
    • getTransitiveDepth

      public abstract org.gradle.api.provider.Property<Integer> getTransitiveDepth()
      How many levels of transitive dependencies to follow when the transitive strategy 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
    • getTestSuffixes

      public abstract org.gradle.api.provider.ListProperty<String> getTestSuffixes()
      Test class suffixes used by the naming strategy. Default: ["Test", "IT", "ITTest", "IntegrationTest"].
      Returns:
      the test suffixes list property
    • getSourceDirs

      public abstract org.gradle.api.provider.ListProperty<String> getSourceDirs()
      Production source directories (relative to each module root). Default: ["src/main/java"].
      Returns:
      the source dirs list property
    • getTestDirs

      public abstract org.gradle.api.provider.ListProperty<String> getTestDirs()
      Test source directories (relative to each module root). Default: ["src/test/java"].
      Returns:
      the test dirs list property
    • getIgnorePaths

      public abstract org.gradle.api.provider.ListProperty<String> 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 through Situation.ALL_FILES_IGNORED.

      When unset, the core AffectedTestsConfig default list applies (markdown, generated/, text/licence/changelog, images).

      Returns:
      the ignore paths list property
    • getOutOfScopeTestDirs

      public abstract org.gradle.api.provider.ListProperty<String> getOutOfScopeTestDirs()
      Test source directories (e.g. "api-test/src/test/java") whose contents the plugin must not dispatch via the affectedTest task. A diff entirely under these directories routes through Situation.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

      public abstract org.gradle.api.provider.ListProperty<String> getOutOfScopeSourceDirs()
      Production source directories the plugin must treat as out-of-scope. A diff entirely under these dirs routes through Situation.ALL_FILES_OUT_OF_SCOPE.
      Returns:
      the out-of-scope source dirs list property
    • getIncludeImplementationTests

      public abstract org.gradle.api.provider.Property<Boolean> getIncludeImplementationTests()
      Include tests for implementations of changed interfaces/base classes. Default: true.
      Returns:
      the include implementation tests property
    • getImplementationNaming

      public abstract org.gradle.api.provider.ListProperty<String> getImplementationNaming()
      Implementation naming prefixes/suffixes (e.g. "Impl" matches FooBarImpl for FooBar; "Default" matches DefaultFooBar for FooBar). Default: ["Impl", "Default"].
      Returns:
      the implementation naming list property
    • getMode

      public abstract org.gradle.api.provider.Property<String> getMode()
      Execution profile ("auto", "local", "ci", or "strict"). Controls per-situation default actions when the explicit onXxx setting is not set.

      Default: unset — which resolves to Mode.AUTO on the core config. AUTO detects CI via common env vars and picks the CI defaults there, and the LOCAL defaults otherwise.

      Returns:
      the mode property
    • getOnEmptyDiff

      public abstract org.gradle.api.provider.Property<String> getOnEmptyDiff()
      Action to take on an empty git diff. One of "selected", "full_suite", "skipped" (case-insensitive).
      Returns:
      the on-empty-diff property
    • getOnAllFilesIgnored

      public abstract org.gradle.api.provider.Property<String> getOnAllFilesIgnored()
      Action to take when every file in the diff matched getIgnorePaths(). One of "selected", "full_suite", "skipped".
      Returns:
      the on-all-files-ignored property
    • getOnAllFilesOutOfScope

      public abstract org.gradle.api.provider.Property<String> getOnAllFilesOutOfScope()
      Action to take when every file in the diff sat under getOutOfScopeTestDirs() or getOutOfScopeSourceDirs(). One of "selected", "full_suite", "skipped".
      Returns:
      the on-all-files-out-of-scope property
    • getOnUnmappedFile

      public abstract org.gradle.api.provider.Property<String> 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-v2 runAllOnNonJavaChange=false behaviour.
      Returns:
      the on-unmapped-file property
    • getOnDiscoveryEmpty

      public abstract org.gradle.api.provider.Property<String> getOnDiscoveryEmpty()
      Action to take when discovery completes but returns no tests. One of "selected", "full_suite", "skipped".
      Returns:
      the on-discovery-empty property
    • getOnDiscoveryIncomplete

      public abstract org.gradle.api.provider.Property<String> getOnDiscoveryIncomplete()
      Action to take when discovery ran but at least one scanned Java file failed to parse — see Situation.DISCOVERY_INCOMPLETE on the core module for the full rationale. One of "selected", "full_suite", "skipped".

      Unset falls through to the mode default (CI and STRICT escalate to full_suite; LOCAL keeps the partial selection).

      Returns:
      the on-discovery-incomplete property
    • getGradlewTimeoutSeconds

      public abstract org.gradle.api.provider.Property<Long> getGradlewTimeoutSeconds()
      Wall-clock timeout in seconds for the nested ./gradlew invocation that executes the affected / full test suite. 0 disables 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 core config builder rejects negative values at build-config time.

      Returns:
      the gradlew timeout property in seconds