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
-
Download zip file: ksp-repro.zip
-
Initial Build: Run a clean build with build cache enabled.
./gradlew clean build --build-cache
Expectation: All generated files (ClassA_Generated.kt, ClassB_Generated.kt) are created and cached.
-
Edit: Modify a single source file (e.g., ClassA.kt). I added a new property: val c = "123"
-
Incremental Build: Run an incremental build with build cache enabled.
./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
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
Download zip file: ksp-repro.zip
Initial Build: Run a clean build with build cache enabled.
Expectation: All generated files (
ClassA_Generated.kt,ClassB_Generated.kt) are created and cached.Edit: Modify a single source file (e.g.,
ClassA.kt). I added a new property:val c = "123"Incremental Build: Run an incremental build with build cache enabled.
Expectation: KSP processes the change.
Issue: KSP fails to preserve
ClassB_Generated.ktin the output directory becauseClassB.ktwas not modified. The build cache snapshot taken after this run only containsClassA_Generated.ktand the build fails