Gradle plugin: don't register generated sources via generatedKotlin on KSP projects#3665
Merged
Merged
Conversation
…n KSP projects KSP doesn't know about Kotlin 2.3's KotlinSourceSet.generatedKotlin, so registering Wire's output there (since 7.0.0-alpha01) has two effects on projects applying KSP: - Wire-generated sources are invisible to symbol processors. - KSP tasks lose the dependency on the Wire task they used to get from the kotlin.srcDir() registration. Builds which also reference Wire's output directory from another source set — a common pattern — then fail Gradle's execution-time dependency validation: "Task ':kspKotlin' uses this output of task ':generateMainProtos' without declaring an explicit or implicit dependency". Fall back to kotlin.srcDir(), the Wire 6 behavior, when the KSP plugin is applied. Projects without KSP keep the generatedKotlin registration and its IDE benefits.
oldergod
force-pushed
the
bquenaudon.2026-07-22.ksp-generated-kotlin
branch
from
July 22, 2026 10:07
6d7d63c to
07d283f
Compare
oldergod
marked this pull request as ready for review
July 22, 2026 10:08
dnkoutso
approved these changes
Jul 22, 2026
oldergod
enabled auto-merge
July 22, 2026 10:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since 7.0.0-alpha01 (#3573), on Kotlin 2.3+ the Gradle plugin registers its generated Kotlin sources via
KotlinSourceSet.generatedKotlininstead ofkotlin.srcDir(). KSP (KSP1 and KSP2 alike) doesn't know aboutgeneratedKotlin, which has two effects on projects applying KSP:sourceSet.kotlin; thekotlin.srcDir(provider)registration was what carried the edge togenerateProtos. Builds which also reference Wire's output directory from another source set — a common real-world pattern, e.g.sourceSets.main.java.srcDir(layout.buildDirectory.dir("generated/source/wire"))— now fail Gradle's execution-time dependency validation:Found rolling Wire 7.0.0-alpha06 out to Cash's server monorepo, where this failed exactly as above on Kotlin/KSP 2.3.10 with Gradle 9.4.
Fix
When the
com.google.devtools.kspplugin is applied, fall back to thekotlin.srcDir()registration — the Wire 6 behavior every KSP user had. Projects without KSP keep thegeneratedKotlinregistration and its IDE benefits. This mirrors the Android-side decision from #3611, where sources are registered onvariant.sources.javaspecifically so KSP can see them.The long-term resolution is for KSP to support
generatedKotlin(collect its directories and carry their task dependencies); this fallback can be removed once it does.Testing
New
kotlin-project-kotlin-protos-kgp23-kspfixture: KGP 2.3.10 + KSP2 2.3.10 (ksp.useKSP2=true) with a Moshi codegen processor, plus the plain-path source-set registration pattern from the wild. Against the unfixed plugin it fails with exactly the validation error above; with the fix, the fixture and the two existinggeneratedKotlin/fallback tests all pass. The fix was also verified against the failing Cash monorepo module by republishing the plugin locally.