Skip to content

Gradle plugin: don't register generated sources via generatedKotlin on KSP projects#3665

Merged
oldergod merged 1 commit into
masterfrom
bquenaudon.2026-07-22.ksp-generated-kotlin
Jul 22, 2026
Merged

Gradle plugin: don't register generated sources via generatedKotlin on KSP projects#3665
oldergod merged 1 commit into
masterfrom
bquenaudon.2026-07-22.ksp-generated-kotlin

Conversation

@oldergod

@oldergod oldergod commented Jul 22, 2026

Copy link
Copy Markdown
Member

Problem

Since 7.0.0-alpha01 (#3573), on Kotlin 2.3+ the Gradle plugin registers its generated Kotlin sources via KotlinSourceSet.generatedKotlin instead of kotlin.srcDir(). KSP (KSP1 and KSP2 alike) doesn't know about generatedKotlin, which has two effects on projects applying KSP:

  1. Wire-generated sources are invisible to symbol processors — they are no longer part of the source roots KSP collects.
  2. KSP tasks lose their task dependency on the Wire task. KSP wires its dependencies from sourceSet.kotlin; the kotlin.srcDir(provider) registration was what carried the edge to generateProtos. 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:
A problem was found with the configuration of task ':kspKotlin' (type 'KspAATask').
  - Gradle detected a problem with the following location: '…/build/generated/source/wire'.
    Reason: Task ':kspKotlin' uses this output of task ':generateMainProtos' without declaring an
    explicit or implicit dependency.

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.ksp plugin is applied, fall back to the kotlin.srcDir() registration — the Wire 6 behavior every KSP user had. Projects without KSP keep the generatedKotlin registration and its IDE benefits. This mirrors the Android-side decision from #3611, where sources are registered on variant.sources.java specifically 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-ksp fixture: 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 existing generatedKotlin/fallback tests all pass. The fix was also verified against the failing Cash monorepo module by republishing the plugin locally.

…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
oldergod force-pushed the bquenaudon.2026-07-22.ksp-generated-kotlin branch from 6d7d63c to 07d283f Compare July 22, 2026 10:07
@oldergod
oldergod requested review from dnkoutso and staktrace July 22, 2026 10:08
@oldergod
oldergod marked this pull request as ready for review July 22, 2026 10:08
@oldergod
oldergod enabled auto-merge July 22, 2026 10:52
@oldergod
oldergod merged commit 33688bf into master Jul 22, 2026
17 checks passed
@oldergod
oldergod deleted the bquenaudon.2026-07-22.ksp-generated-kotlin branch July 22, 2026 10:55
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.

2 participants