KSP Incremental Build Cache Issue
- Dominant language
- Kotlin
- Stars
- 3.5k
- Forks
- 415
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 53
Description
## Description
When running KSP in an incremental setup, the build cache snapshot taken after an incremental run can be incomplete. Specifically, if a source file is edited, KSP2 may delete or fail to preserve generated outputs for *unmodified* source files. When Gradle takes a snapshot of the output directory after this incremental run, it only captures the newly generated files. If there are code dependencies on the missing file, downstream compilation tasks will fail immediately during the incremental run, or after restoring from cache (e.g., "Unresolved reference").
## Steps to Reproduce
0. **Download zip file**: [ksp-repro.zip](https://github.com/user-attachments/files/26436720/ksp-repro.zip)
1. **Initial Build**: Run a clean build with build cache enabled.
```bash
./gradlew clean build --build-cache
```
*Expectation*: All generated files (`ClassA_Generated.kt`, `ClassB_Generated.kt`) are created and cached.
2. **Edit**: Modify a single source file (e.g., `ClassA.kt`). I added a new property: `val c = "123"`
3. **Incremental Build**: Run an incremental build with build cache enabled.
```bash
./gradlew build --build-cache
```
*Expectation*: KSP processes the change.
*Issue*: KSP fails to preserve `ClassB_Generated.kt` in the output directory because `ClassB.kt` was not modified. The build cache snapshot taken after this run only contains `ClassA_Generated.kt` and the build fails
Contributor guide
Assessment
This issue has not been assessed yet.