Skip to content

Fix classpath when source set has no metadata compilations#4296

Merged
adam-enko merged 11 commits intomasterfrom
adam/fix-classpath-without-metadata-compilations
Jan 8, 2026
Merged

Fix classpath when source set has no metadata compilations#4296
adam-enko merged 11 commits intomasterfrom
adam/fix-classpath-without-metadata-compilations

Conversation

@adam-enko
Copy link
Member

@adam-enko adam-enko commented Oct 14, 2025

This PR contains a fix for two situations where a source set's classpath does not contain the required KMP klibs for Dokka to resolve symbols in the source set's code.

Fix 'bamboo' source sets.

If an intermediate source set only has one actual KMP target this is informally known as a 'bamboo' source set (because, unlike a 'tree', a bamboo does not have branches).

For example, windowsMain and mingwMain only have one target: mingwX64Main.

In KotlinAdapter an intermediate source set does not have any primaryCompilations.
If an intermediate source set only has a single 'associated compilation' then it will be considered as a 'bamboo' source set. The single 'associated compilation' is the actual target compilation. and DGP will use the classpath of actual target.

Fixes #3386

Workaround no metadata compilations for shared Wasm source sets (workaround for KT-80551)

KGP registers metadata compilations for source sets that have multiple native compilations, but not for multiple wasm source sets.

This PR works around this by using an internal KGP function to register the metadata compilation for shared wasm source sets.

Workaround for:

Stop adding source directories to classpath

For some reason DGPv2 adds source directories to the classpath. I didn't dig into the reason, but it seems to have no purpose. So I just removed this:

https://github.com/Kotlin/dokka/blob/v2.1.0/dokka-runners/dokka-gradle-plugin/src/main/kotlin/adapters/KotlinAdapter.kt#L204-L206

Fix and update kotlin-multiplatform-example

  • Update kotlin-multiplatform-example to be compilable (it wasn't compilable before!)
  • Add 'webMain' test.

@adam-enko adam-enko added the runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin label Oct 14, 2025
@adam-enko adam-enko changed the base branch from master to adam/support-agp-kotlin-builtin October 14, 2025 15:28
@whyoleg

This comment was marked as outdated.

@adam-enko adam-enko force-pushed the adam/support-agp-kotlin-builtin branch from 12c2bb1 to 4dd9e43 Compare November 5, 2025 09:26
@adam-enko adam-enko force-pushed the adam/fix-classpath-without-metadata-compilations branch from 4cddab4 to 685f09b Compare November 6, 2025 17:03
@adam-enko adam-enko force-pushed the adam/support-agp-kotlin-builtin branch from d2b6dd7 to 747573f Compare November 10, 2025 17:38
@adam-enko adam-enko self-assigned this Nov 10, 2025
@adam-enko adam-enko force-pushed the adam/fix-classpath-without-metadata-compilations branch from 685f09b to 62d4bff Compare November 10, 2025 18:02
@adam-enko adam-enko force-pushed the adam/fix-classpath-without-metadata-compilations branch from d249aa3 to ab74561 Compare November 24, 2025 18:36
@adam-enko adam-enko changed the base branch from adam/support-agp-kotlin-builtin to master November 24, 2025 18:37
@adam-enko adam-enko marked this pull request as ready for review November 25, 2025 08:04
Copy link
Collaborator

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look on the comment in KotlinAdapter

@adam-enko adam-enko force-pushed the adam/fix-classpath-without-metadata-compilations branch from 452538e to 55e4830 Compare November 26, 2025 15:07
@adam-enko
Copy link
Member Author

I've discussed more with @abdulowork and we think we've found a better workaround. We can use IdeMultiplatformImport to get the same data that IJ uses.

I'll have another attempt...

@adam-enko adam-enko marked this pull request as draft November 26, 2025 17:12
@adam-enko
Copy link
Member Author

Unfortunately while IdeMultiplatformImport returns the required klibs, it doesn't seem to be very stable. The KGP task that uses IdeMultiplatformImport disables CC and caching. In DGP it triggers lots of warnings when used with AGP:

Configuration 'jvmCompileClasspath' was resolved during configuration time.
This is a build performance and scalability issue.
See https://github.com/gradle/gradle/issues/2298

Investigations are ongoing...

### Fix 'bamboo' source sets.

If an intermediate source set only has one actual KMP target this is informally known as a 'bamboo' source set (because, unlike a 'tree', a bamboo does not have branches).

For example, `windowsMain` and `mingwMain` only have one target: `mingwX64Main`.

In `KotlinAdapter` an intermediate source set does not have any `primaryCompilations`.
If an intermediate source set only has a single 'associated compilation' then it will be considered as a 'bamboo' source set. The single 'associated compilation' is the actual target compilation. and DGP will use the classpath of actual target.

### Workaround no metadata compilations for shared Wasm source sets (workaround for KT-80551)

KGP registers metadata compilations for source sets that have multiple native compilations, but _not_ for multiple wasm source sets.

This PR works around this by using an `internal` KGP function to register the metadata compilation for shared wasm source sets.

Workaround for:

- https://youtrack.jetbrains.com/issue/KT-80551
- #4116

### Stop adding source directories to classpath

For some reason DGPv2 adds source directories to the classpath. I didn't dig into the reason, but it seems to have no purpose. So I just removed this:

https://github.com/Kotlin/dokka/blob/v2.1.0/dokka-runners/dokka-gradle-plugin/src/main/kotlin/adapters/KotlinAdapter.kt#L204-L206
…pilable before!)

- Add 'webMain' source set.
@adam-enko adam-enko force-pushed the adam/fix-classpath-without-metadata-compilations branch from 54135fe to c49cefc Compare December 18, 2025 10:43
@adam-enko adam-enko marked this pull request as ready for review December 18, 2025 16:38
@adam-enko adam-enko requested a review from antohaby December 18, 2025 16:38
@whyoleg whyoleg self-requested a review December 22, 2025 10:40
Copy link
Collaborator

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the changes appear to be fine, and the workaround for the problem seems quite isolated.
The only thing that bothers me is that it looks like the fix on the KGP side - just compiling wasmJs + wasmWasi as if it were wasmWasi + native, e.g., via metadata compilation - might have been easier :)

…()` in separate file to avoid file-level `internal` suppression, and add failure handling inside `map {}`.
@adam-enko
Copy link
Member Author

Failing tests are due to the year change, and are fixed by #4406

Copy link
Collaborator

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the hard work on finding how to fix this on Dokka side!

@whyoleg whyoleg linked an issue Jan 8, 2026 that may be closed by this pull request
@adam-enko adam-enko merged commit d67cf0c into master Jan 8, 2026
30 checks passed
@adam-enko adam-enko deleted the adam/fix-classpath-without-metadata-compilations branch January 8, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[K2] kotlinx-io: Error classes on Wasm platform [K2] KMP: Extension function miss platform tab for shared source set with one target

2 participants