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"
     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 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: true.
      Returns:
      the include uncommitted property
    • getIncludeStaged

      public abstract org.gradle.api.provider.Property<Boolean> getIncludeStaged()
      Include staged changes. Default: true.
      Returns:
      the include staged property
    • getRunAllIfNoMatches

      public abstract org.gradle.api.provider.Property<Boolean> getRunAllIfNoMatches()
      Run full test suite if no affected tests are found. Default: false.
      Returns:
      the run-all-if-no-matches property
    • getRunAllOnNonJavaChange

      public abstract org.gradle.api.provider.Property<Boolean> getRunAllOnNonJavaChange()
      Force a full test run whenever the change set contains any file that cannot be resolved to a Java class under getSourceDirs() or getTestDirs() — for example application.yml, build.gradle, a Liquibase changelog, or a logback config. Files matching getExcludePaths() 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

      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: 2. 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
    • getExcludePaths

      @Deprecated public abstract org.gradle.api.provider.ListProperty<String> getExcludePaths()
      Deprecated.
      prefer getIgnorePaths() in new configs.
      Glob patterns for files to exclude from analysis. v2 back-compat alias for getIgnorePaths(). Default is an empty Gradle property — when unset, the v2 ignorePaths default applies (a broader list than the pre-v2 single-entry ["**/generated/**"] list).
      Returns:
      the exclude paths 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 neither the explicit onXxx setting 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

      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