From 08f531bbffc2ed4158075708cedae71d7f44ec03 Mon Sep 17 00:00:00 2001 From: Adam Semenenko <152864218+adam-enko@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:18:01 +0100 Subject: [PATCH] enable KlibsCrossCompilation for kmp example --- .../kotlin/ExampleProjectsTest.kt | 34 ++++++++++++++----- .../kotlin/GradlePropertiesBuilder.kt | 9 ++++- .../build.gradle.kts | 2 +- .../gradle.properties | 6 ++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/dokka-integration-tests/gradle/src/testExampleProjects/kotlin/ExampleProjectsTest.kt b/dokka-integration-tests/gradle/src/testExampleProjects/kotlin/ExampleProjectsTest.kt index 19cf1c44a5..35d0ac7f23 100644 --- a/dokka-integration-tests/gradle/src/testExampleProjects/kotlin/ExampleProjectsTest.kt +++ b/dokka-integration-tests/gradle/src/testExampleProjects/kotlin/ExampleProjectsTest.kt @@ -122,6 +122,28 @@ class ExampleProjectsTest { ExampleProject.CompositeBuild -> ":build" else -> ":dokkaGenerate" } + + init { + updateGradleProperties() + } + + private fun updateGradleProperties() { + when (exampleProjectName) { + ExampleProject.KotlinMultiplatform -> { + project.gradleProperties { + // kotlin.native.enableKlibsCrossCompilation must be set to `true` + // otherwise Kotlin can't generate a Klib for Coroutines in macosMain + // when generating on Linux machines, resulting in 'Error class: unknown class' + // for CoroutineScope appearing in the generated docs. + kotlin.native.enableKlibsCrossCompilation = true + } + } + + else -> {} + } + + project.runner.writeGradleProperties(project.gradleProperties) + } } /** @@ -170,9 +192,8 @@ class ExampleProjectsTest { format = "html", ) - verifyNoUnknownClassErrorsInHtmlFiles( - testCase = testCase, - format = "html", + verifyNoUnknownClassErrorsInHtml( + dokkaOutputDir = testCase.dokkaOutputDir.resolve("html") ) } @@ -237,12 +258,9 @@ class ExampleProjectsTest { } } - private fun verifyNoUnknownClassErrorsInHtmlFiles( - testCase: TestCase, - format: String, + private fun verifyNoUnknownClassErrorsInHtml( + dokkaOutputDir: Path, ) { - val dokkaOutputDir = testCase.dokkaOutputDir.resolve(format) - withClue("expect no 'unknown class' message in output files") { val htmlFiles = dokkaOutputDir.walk() .filter { it.isRegularFile() && it.extension == "html" } diff --git a/dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradlePropertiesBuilder.kt b/dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradlePropertiesBuilder.kt index 5c57cb9afe..ec18f48b28 100644 --- a/dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradlePropertiesBuilder.kt +++ b/dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradlePropertiesBuilder.kt @@ -57,7 +57,13 @@ data class GradlePropertiesBuilder( /** Kotlin specific options. */ data class KotlinArgs( var mppStabilityWarning: Boolean? = true, - ) + val native: NativeArgs = NativeArgs(), + ) { + + data class NativeArgs( + var enableKlibsCrossCompilation: Boolean? = null + ) + } /** Dokka specific options. */ data class DokkaArgs( @@ -105,6 +111,7 @@ data class GradlePropertiesBuilder( with(kotlin) { putNotNull("kotlin.mpp.stability.nowarn", mppStabilityWarning?.let { !it }) + putNotNull("kotlin.native.enableKlibsCrossCompilation", native.enableKlibsCrossCompilation) } with(gradle) { diff --git a/examples/gradle-v2/kotlin-multiplatform-example/build.gradle.kts b/examples/gradle-v2/kotlin-multiplatform-example/build.gradle.kts index e6fac67c31..0be6b4713a 100644 --- a/examples/gradle-v2/kotlin-multiplatform-example/build.gradle.kts +++ b/examples/gradle-v2/kotlin-multiplatform-example/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") version "1.9.25" + kotlin("multiplatform") version "2.1.0" id("org.jetbrains.dokka") version "2.0.20-SNAPSHOT" } diff --git a/examples/gradle-v2/kotlin-multiplatform-example/gradle.properties b/examples/gradle-v2/kotlin-multiplatform-example/gradle.properties index 1ff33cc762..53a88880f5 100644 --- a/examples/gradle-v2/kotlin-multiplatform-example/gradle.properties +++ b/examples/gradle-v2/kotlin-multiplatform-example/gradle.properties @@ -5,3 +5,9 @@ org.gradle.parallel=true org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true + +# kotlin.native.enableKlibsCrossCompilation must be set to `true` +# otherwise Kotlin can't generate a Klib for Coroutines in macosMain +# when generating on Linux machines, resulting in 'Error class: unknown class' +# for CoroutineScope appearing in the generated docs. +kotlin.native.enableKlibsCrossCompilation=true