google / google/ksp

KSP missing generated sources after Gradle incremental compilation

Open
#2,536 3 comments 5 reactions 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

For details see https://github.com/google/dagger/issues/4878 and the repro example:

https://github.com/sam-step/dagger-ksp-incremental-repro

To make it easier to see the dependency tree I'll put it below:

Image

If we do a clean build, everything builds fine. If we then trigger an incremental build by modifying only `OtherClass.kt` we get the following error:

```
> Task :app:kspKotlin FAILED
e: [ksp] ComponentProcessingStep was unable to process 'app.MyComponent' because 'generated.Generated_AnnotatedClassModule' could not be resolved.
```

The log files comparing the clean build to the incremental change are shown below.

**Note:** there's no `kspSourceToOutputs.log` entry for "`Build 1753820315477`"

### kspDirtySet.log

```
=== Build 1753820260259 ===
All Files
src/main/kotlin/app/App.kt
src/main/kotlin/app/AnnotatedClass.kt
src/main/kotlin/app/OtherClass.kt
src/main/kotlin/app/MyComponent.kt
src/main/kotlin/app/TargetAnnotation.kt
src/main/kotlin/app/ClassProvidedByGeneratedModule.kt
Modified
Removed
Disappeared Outputs
Affected By CP
Affected By new syms
Affected By sealed
CP changes
Dirty:
src/main/kotlin/app/App.kt
src/main/kotlin/app/AnnotatedClass.kt
src/main/kotlin/app/OtherClass.kt
src/main/kotlin/app/MyComponent.kt
src/main/kotlin/app/TargetAnnotation.kt
src/main/kotlin/app/ClassProvidedByGeneratedModule.kt

Dirty / All: 100.00%

=== Build 1753820315477 ===
All Files
src/main/kotlin/app/App.kt
src/main/kotlin/app/AnnotatedClass.kt
src/main/kotlin/app/OtherClass.kt
src/main/kotlin/app/MyComponent.kt
src/main/kotlin/app/TargetAnnotation.kt
src/main/kotlin/app/ClassProvidedByGeneratedModule.kt
Modified
src/main/kotlin/app/OtherClass.kt
Removed
Disappeared Outputs
Affected By CP
Affected By new syms
src/main/kotlin/app/MyComponent.kt
Affected By sealed
CP changes
Dirty:
src/main/kotlin/app/OtherClass.kt
src/main/kotlin/app/MyComponent.kt

Dirty / All: 33.33%
```

### kspSourceToOutputs.log

```
=== Build 1753820260259 ===
Accumulated source to outputs map
:
src/main/kotlin/app/AnnotatedClass.kt:
build/generated/ksp/main/kotlin/app/generated/Generated_AnnotatedClassModule.kt
src/main/kotlin/app/OtherClass.kt:
build/generated/ksp/main/java/app/OtherClass_Factory.java
build/generated/ksp/main/kotlin/app/generated/Generated_AnnotatedClassModule.kt:
build/generated/ksp/main/java/app/generated/Generated_AnnotatedClassModule_ProvideFactory.java
src/main/kotlin/app/MyComponent.kt:
build/generated/ksp/main/java/app/DaggerMyComponent.java

Reprocessed sources and their outputs
src/main/kotlin/app/AnnotatedClass.kt:
build/generated/ksp/main/kotlin/app/generated/Generated_AnnotatedClassModule.kt
src/main/kotlin/app/OtherClass.kt:
build/generated/ksp/main/java/app/OtherClass_Factory.java
build/generated/ksp/main/kotlin/app/generated/Generated_AnnotatedClassModule.kt:
build/generated/ksp/main/java/app/generated/Generated_AnnotatedClassModule_ProvideFactory.java
src/main/kotlin/app/MyComponent.kt:
build/generated/ksp/main/java/app/DaggerMyComponent.java

All reprocessed outputs
build/generated/ksp/main/kotlin/app/generated/Generated_AnnotatedClassModule.kt
build/generated/ksp/main/java/app/OtherClass_Factory.java
build/generated/ksp/main/java/app/generated/Generated_AnnotatedClassModule_ProvideFactory.java
build/generated/ksp/main/java/app/DaggerMyComponent.java
```

From the error message and logs it seems like the `Generated_AnnotatedClassModule` output was cleared/removed, but that seems wrong since `AnnotatedClass` isn't dirty and isn't reprocessed by the incremental change.

Contributor guide

Open the contributing guide

Research direction

Start with the linked repro repository and compare the clean and incremental runs using kspDirtySet.log and kspSourceToOutputs.log. Read the related google/dagger#4878 issue and trace how the generated Generated_AnnotatedClassModule output is handled when only OtherClass.kt changes. Done means the incremental build retains or correctly regenerates that output and the app:kspKotlin task succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.