Skip to content

Preserve all originating elements for KSP incremental processing - #5360

Closed
nolanpollack-stripe wants to merge 1 commit into
google:masterfrom
nolanpollack-stripe:fix-originating-elements
Closed

nolanpollack-stripe wants to merge 1 commit into
google:masterfrom
nolanpollack-stripe:fix-originating-elements

Conversation

@nolanpollack-stripe

@nolanpollack-stripe nolanpollack-stripe commented Nov 16, 2026 •

Copy link
Copy Markdown

XTypeSpecs.Builder.addOriginatingElement() currently overwrites the previous element.

Components with multiple generated modules therefore lose input dependencies needed by KSP incremental processing. Editing only the component can make the next build fail because an unchanged generated module is missing.

The fix keeps all originating elements.

Fixes #5363.

This was triggered when TypeSpec was migrated to XTypeSpec in 7c4622d. Javapoet's addOriginatingElement correctly tracks elements as a list.

https://github.com/square/javapoet/blob/b9017a9503b76e11b4ad4c1a9f050e2d29112cb0/src/main/java/com/squareup/javapoet/TypeSpec.java#L429

Validation:

  • The new Gradle regression fails with the unpatched compiler on its second build: ActivityModule_Activity could not be resolved. It passes with this patch using Kotlin 2.3.21 and KSP 2.3.7.
  • Both tests in IncrementalProcessingTest pass against the patched local snapshot.
  • Bazel tests pass: XTypeSpecsTest, XCodeBlocksTest, XMethodElementsTest, ComponentProcessorTest, ComponentShardTest, and KspComponentProcessorTest.
  • git diff --check passes.

@google-cla

google-cla Bot commented Nov 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@nolanpollack-stripe
nolanpollack-stripe marked this pull request as ready for review November 16, 2026 22:34
copybara-service Bot pushed a commit that referenced this pull request Nov 19, 2026
Add Gradle TestKit regression tests in `IncrementalProcessingTest` covering two distinct KSP incremental module resolution scenarios:
- Explicitly referenced `@Module` generated by another non-dirtied KSP processor (#4878 / google/ksp#2536).
- Multiple `@ContributesAndroidInjector` modules implicitly included in a component (#4181 / #5360).

RELNOTES=N/A
PiperOrigin-RevId: 1025866242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KSP incremental build fails to resolve generated modules when multiple @ContributesAndroidInjector modules are included

1 participant