aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-08-04 18:57:00 +0200
committerGitHub <noreply@github.com>2023-08-04 18:57:00 +0200
commitb559131ddda8efea3394a0ea641460c4189769db (patch)
treebf6f6d57975c266fd069b27d9f1365f6d104701e
parent0be397336e89782cda94c8bf55005a2be9abecde (diff)
downloaddokka-b559131ddda8efea3394a0ea641460c4189769db.tar.gz
dokka-b559131ddda8efea3394a0ea641460c4189769db.tar.bz2
dokka-b559131ddda8efea3394a0ea641460c4189769db.zip
Make the compatibility metadata variant check more specific (#3103)
-rw-r--r--integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts3
-rw-r--r--integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt3
-rw-r--r--runners/gradle-plugin/api/gradle-plugin.api4
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt13
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt34
5 files changed, 36 insertions, 21 deletions
diff --git a/integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts b/integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts
index bed3c9b1..fd34b3bc 100644
--- a/integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts
+++ b/integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts
@@ -14,7 +14,6 @@ repositories {
}
kotlin {
- jvm() // artificial empty target to avoid single target project
wasm()
sourceSets {
val wasmMain by getting {
@@ -45,4 +44,4 @@ configurations.all {
useVersion(project.properties["dokka_it_kotlin_version"] as String)
}
}
-} \ No newline at end of file
+}
diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt
index f4774dff..00cc779a 100644
--- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt
+++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt
@@ -10,7 +10,8 @@ class WasmGradleIntegrationTest(override val versions: BuildVersions) : Abstract
companion object {
@get:JvmStatic
@get:Parameters(name = "{0}")
- val versions = listOf(TestedVersions.LATEST)
+ val versions = TestedVersions.ALL_SUPPORTED
+ .filter { it.kotlinVersion >= "1.8.20" } // 1.8.20 is the first public version that can be tested with wasm
}
@BeforeTest
diff --git a/runners/gradle-plugin/api/gradle-plugin.api b/runners/gradle-plugin/api/gradle-plugin.api
index d7d38d2f..0ec172b7 100644
--- a/runners/gradle-plugin/api/gradle-plugin.api
+++ b/runners/gradle-plugin/api/gradle-plugin.api
@@ -179,7 +179,3 @@ public final class org/jetbrains/dokka/gradle/internal/AbstractDokkaTaskExtensio
public static synthetic fun buildJsonConfiguration$default (Lorg/jetbrains/dokka/gradle/AbstractDokkaTask;ZILjava/lang/Object;)Ljava/lang/String;
}
-public final class org/jetbrains/dokka/gradle/kotlin/KotlinClasspathUtilsKt {
- public static final fun isHMPPEnabled (Lorg/gradle/api/Project;)Z
-}
-
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
index b534dcc4..1d1d18fc 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
@@ -5,25 +5,12 @@ import org.gradle.api.file.FileCollection
import org.jetbrains.dokka.gradle.isAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
-import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-val Project.isHMPPEnabled
- // [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this
- get() = (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false
-
internal fun Project.classpathOf(sourceSet: KotlinSourceSet): FileCollection {
val compilations = compilationsOf(sourceSet)
return if (compilations.isNotEmpty()) {
compilations
- /**
- * If the project has enabled Compatibility Metadata Variant (produces legacy variant),
- * we don't touch it due to some dependant library
- * might be published without Compatibility Metadata Variant.
- * Dokka needs only HMPP variant
- * Ignore [org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation] for `commonMain` sourceSet with name `main`
- */
- .filterNot { compilation -> isHMPPEnabled && compilation is KotlinCommonCompilation && compilation.name == "main" }
.map { compilation -> compilation.compileClasspathOf(project = this) }
.reduce { acc, fileCollection -> acc + fileCollection }
} else {
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt
index 1d06e608..ab781432 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt
@@ -6,15 +6,47 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
+import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
internal typealias KotlinCompilation =
org.jetbrains.kotlin.gradle.plugin.KotlinCompilation<KotlinCommonOptions>
internal fun Project.compilationsOf(sourceSet: KotlinSourceSet): List<KotlinCompilation> {
//KT-45412 Make sure .kotlinSourceSets and .allKotlinSourceSets include the default source set
- return allCompilationsOf(sourceSet).filter { compilation ->
+ val compilations = allCompilationsOf(sourceSet).filter { compilation ->
sourceSet in compilation.kotlinSourceSets || sourceSet == compilation.defaultSourceSet
}
+
+ val hasAdditionalCommonCompatibilityMetadataVariant = compilations.size >= 2
+ && this.isHmppEnabled()
+ && compilations.any { it is KotlinCommonCompilation && it.compilationName == "main" }
+ && compilations.any { it is KotlinCommonCompilation && it.compilationName == "commonMain" }
+
+ return if (hasAdditionalCommonCompatibilityMetadataVariant) {
+ // If the project has `kotlin.mpp.enableCompatibilityMetadataVariant` set to `true`
+ // and it produces a legacy variant for common, we filter it out because one of the dependencies
+ // might be published without it, and it would lead to the following error:
+ //
+ // > Execution failed for task ':project:dokkaHtmlPartial'.
+ // > Could not resolve all files for configuration ':project:metadataCompileClasspath'.
+ // > Could not resolve com.example.dependency:0.1.0.
+ // > The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for
+ // non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we
+ // cannot choose between the following variants of com.example.dependency:0.1.0:
+ //
+ // This can be reproduced consistently on Ktor of version 2.3.2
+ compilations.filterNot { it is KotlinCommonCompilation && it.compilationName == "main" }
+ } else {
+ compilations
+ }
+}
+
+private fun Project.isHmppEnabled(): Boolean {
+ // [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this property instead.
+ // The property name might seem misleading, but it's set by KGP if HMPP is enabled:
+ // https://github.com/JetBrains/kotlin/blob/1.9.0/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/hierarchicalStructureMigrationHandling.kt#L33
+ return (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean()
+ ?: false
}
internal fun Project.allCompilationsOf(