Skip to content

KSP Incremental Build Cache Issue #2854

@omarismail94

Description

@omarismail94

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

  1. Download zip file: ksp-repro.zip

  2. 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.

  3. Edit: Modify a single source file (e.g., ClassA.kt). I added a new property: val c = "123"

  4. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions