Getting started
Requirements
| Component | Version |
|---|---|
| Java | 21 or newer |
| Gradle | 9.x. The plugin is built and tested on 9.9.3; older Gradle versions are not tested. |
| Tests | JUnit 5 |
| Source | Java. Kotlin sources are parsed too; .groovy, .kts and .scala files are not mapped to classes yet. |
Spring Boot is not required. The plugin has Spring-aware behaviour for @Configuration and @SpringBootApplication classes, described in Spring and @Bean changes, and works on plain Java projects too.
1. Apply the plugin
plugins {
id 'io.github.vedanthvdev.affectedtests' version 'x.y.z'
}
The same snippet in the Kotlin DSL:
plugins {
id("io.github.vedanthvdev.affectedtests") version "x.y.z"
}
Replace x.y.z with the latest version from the Gradle Plugin Portal or Maven Central. Both channels publish identical, SLSA-attested artifacts from the same CI run, and Maven Central artifacts are also GPG-signed. See SECURITY.md for how to verify them.
2. Run the affected tests
./gradlew affectedTest
With no configuration the plugin:
- diffs
HEADagainstorigin/master, using committed changes only. Uncommitted and staged changes are ignored unless you setincludeUncommittedorincludeStaged; - sorts every changed file into one of five buckets: ignored (
*.md,*.txt,LICENSE,CHANGELOG*, images,**/generated/**), out-of-scope, production.java, test.java, or unmapped (everything else, such asapplication.ymlorbuild.gradle); - finds tests with five strategies (naming, usage, impl, transitive and headerEdges) and merges the results into one set;
- follows transitive dependencies four levels deep, which covers typical controller to service to repository chains;
- runs the full suite when it sees an unmapped file or a changed Spring configuration class, so a YAML, Gradle or Liquibase change never ships without tests.
If your default branch is not origin/master, set it once:
affectedTests {
baseRef = "origin/main"
}
3. See why it chose what it chose
./gradlew affectedTest --explain
--explain prints the full decision trace without running any test: how many files landed in each bucket, the situation, the action, and which setting decided it. Use it when a CI run escalated to the full suite and you need to know why. Add --explain-format=json for a machine-readable version. The --explain page documents both.
Next steps
- Wire it into your pipeline: CI integration.
- Learn what each outcome means: Decision model.
- Tune it: Configuration.
- Try settings on a sample project without installing anything: the playground.