Skip to content

Commit fccbdab

Browse files
committedAug 8, 2023
Make the compatibility metadata variant check more specific (#3103)
(cherry picked from commit b559131)
1 parent a09a068 commit fccbdab

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed
 

‎integration-tests/gradle/projects/it-wasm-basic/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ repositories {
1414
}
1515

1616
kotlin {
17-
jvm() // artificial empty target to avoid single target project
1817
wasm()
1918
sourceSets {
2019
val wasmMain by getting {
@@ -45,4 +44,4 @@ configurations.all {
4544
useVersion(project.properties["dokka_it_kotlin_version"] as String)
4645
}
4746
}
48-
}
47+
}

‎integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class WasmGradleIntegrationTest(override val versions: BuildVersions) : Abstract
1010
companion object {
1111
@get:JvmStatic
1212
@get:Parameters(name = "{0}")
13-
val versions = listOf(TestedVersions.LATEST)
13+
val versions = TestedVersions.ALL_SUPPORTED
14+
.filter { it.kotlinVersion >= "1.8.20" } // 1.8.20 is the first public version that can be tested with wasm
1415
}
1516

1617
@BeforeTest

‎runners/gradle-plugin/api/gradle-plugin.api

-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,3 @@ public final class org/jetbrains/dokka/gradle/internal/AbstractDokkaTaskExtensio
179179
public static synthetic fun buildJsonConfiguration$default (Lorg/jetbrains/dokka/gradle/AbstractDokkaTask;ZILjava/lang/Object;)Ljava/lang/String;
180180
}
181181

182-
public final class org/jetbrains/dokka/gradle/kotlin/KotlinClasspathUtilsKt {
183-
public static final fun isHMPPEnabled (Lorg/gradle/api/Project;)Z
184-
}
185-

‎runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt

-13
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@ import org.gradle.api.file.FileCollection
55
import org.jetbrains.dokka.gradle.isAndroidTarget
66
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
77
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
8-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
98
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
109

11-
val Project.isHMPPEnabled
12-
// [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this
13-
get() = (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false
14-
1510
internal fun Project.classpathOf(sourceSet: KotlinSourceSet): FileCollection {
1611
val compilations = compilationsOf(sourceSet)
1712
return if (compilations.isNotEmpty()) {
1813
compilations
19-
/**
20-
* If the project has enabled Compatibility Metadata Variant (produces legacy variant),
21-
* we don't touch it due to some dependant library
22-
* might be published without Compatibility Metadata Variant.
23-
* Dokka needs only HMPP variant
24-
* Ignore [org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation] for `commonMain` sourceSet with name `main`
25-
*/
26-
.filterNot { compilation -> isHMPPEnabled && compilation is KotlinCommonCompilation && compilation.name == "main" }
2714
.map { compilation -> compilation.compileClasspathOf(project = this) }
2815
.reduce { acc, fileCollection -> acc + fileCollection }
2916
} else {

‎runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt

+33-1
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,47 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
66
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
77
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
88
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
9+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
910

1011
internal typealias KotlinCompilation =
1112
org.jetbrains.kotlin.gradle.plugin.KotlinCompilation<KotlinCommonOptions>
1213

1314
internal fun Project.compilationsOf(sourceSet: KotlinSourceSet): List<KotlinCompilation> {
1415
//KT-45412 Make sure .kotlinSourceSets and .allKotlinSourceSets include the default source set
15-
return allCompilationsOf(sourceSet).filter { compilation ->
16+
val compilations = allCompilationsOf(sourceSet).filter { compilation ->
1617
sourceSet in compilation.kotlinSourceSets || sourceSet == compilation.defaultSourceSet
1718
}
19+
20+
val hasAdditionalCommonCompatibilityMetadataVariant = compilations.size >= 2
21+
&& this.isHmppEnabled()
22+
&& compilations.any { it is KotlinCommonCompilation && it.compilationName == "main" }
23+
&& compilations.any { it is KotlinCommonCompilation && it.compilationName == "commonMain" }
24+
25+
return if (hasAdditionalCommonCompatibilityMetadataVariant) {
26+
// If the project has `kotlin.mpp.enableCompatibilityMetadataVariant` set to `true`
27+
// and it produces a legacy variant for common, we filter it out because one of the dependencies
28+
// might be published without it, and it would lead to the following error:
29+
//
30+
// > Execution failed for task ':project:dokkaHtmlPartial'.
31+
// > Could not resolve all files for configuration ':project:metadataCompileClasspath'.
32+
// > Could not resolve com.example.dependency:0.1.0.
33+
// > The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for
34+
// non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we
35+
// cannot choose between the following variants of com.example.dependency:0.1.0:
36+
//
37+
// This can be reproduced consistently on Ktor of version 2.3.2
38+
compilations.filterNot { it is KotlinCommonCompilation && it.compilationName == "main" }
39+
} else {
40+
compilations
41+
}
42+
}
43+
44+
private fun Project.isHmppEnabled(): Boolean {
45+
// [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this property instead.
46+
// The property name might seem misleading, but it's set by KGP if HMPP is enabled:
47+
// 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
48+
return (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean()
49+
?: false
1850
}
1951

2052
internal fun Project.allCompilationsOf(

0 commit comments

Comments
 (0)
Please sign in to comment.