From 17248c814966b1146368841783c5227c19f4c930 Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Fri, 22 May 2020 12:28:25 +0300 Subject: [PATCH] Fixes for 1.4-M2 & HMPP (#2031) * Gradle 6.3 * Enable Gradle module metadata in all modules * Workaround for gradle/gradle#11412 * Fix invalid mutation of a tasks's dependsOn w/Gradle 6.3 * Rename root MPP module and publish the JVM JAR within * Rename the JVM module: empty suffix -> '-jvm'; * Rename the root MPP module: '-native' -> empty suffix; * Publish the JVM JAR and POM in the root MPP module, so that consumers who can't read Gradle module metadata, such as Maven or old Gradle versions, get the JVM resolution result from the root MPP module. * Enable HMPP * Add jvm attribute to detached configuration Otherwise variant-aware resolution fails to find compatible variant in kotlinx-coroutines-core * Enable HMPP conditionally for Kotlin 1.4.x and not 1.3.7x * Workaround KT-39037 * Disable PrecompiledDebugProbesTest test in train builds * Conditionally hack out the Gradle module metadata with Kotlin 1.3.7x * Conditionally rename Kotlin metadata module to *-metadata with Kotlin 1.4.x * Conditionally rename the root & JVM modules with Kotlin 1.4.x Co-authored-by: Dmitry Savvinov Co-authored-by: Vsevolod Tolstopyatov --- build.gradle | 8 ++++ gradle.properties | 9 +++++ gradle/publish-bintray.gradle | 36 ++++++++++++----- ...publish-mpp-root-module-in-platform.gradle | 39 +++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- integration-testing/build.gradle | 11 +++++- kotlinx-coroutines-core/build.gradle | 11 +++++- 7 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 gradle/publish-mpp-root-module-in-platform.gradle diff --git a/build.gradle b/build.gradle index bc4dd36afc..4dc0481af4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ import org.jetbrains.kotlin.konan.target.HostManager +import org.gradle.util.VersionNumber apply plugin: 'jdk-convention' apply from: rootProject.file("gradle/experimental.gradle") @@ -79,6 +80,11 @@ buildscript { import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +// Hierarchical project structures are not fully supported in 1.3.7x MPP, enable conditionally for 1.4.x +if (VersionNumber.parse(kotlin_version) > VersionNumber.parse("1.3.79")) { + ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true") +} + // todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules def configureKotlinJvmPlatform(configuration) { configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) @@ -192,6 +198,8 @@ if (build_snapshot_train) { exclude '**/*definitely/not/kotlinx*' // Disable because of KT-11567 in 1.4 exclude '**/*CasesPublicAPITest*' + // Kotlin + exclude '**/*PrecompiledDebugProbesTest*' } } diff --git a/gradle.properties b/gradle.properties index 0a45ecd693..bb93165edf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,3 +51,12 @@ jekyll_version=4.0 # JS IR baceknd sometimes crashes with out-of-memory # TODO: Remove once KT-37187 is fixed org.gradle.jvmargs=-Xmx2g + +# Workaround for Bintray treating .sha512 files as artifacts +# https://github.com/gradle/gradle/issues/11412 +systemProp.org.gradle.internal.publish.checksums.insecure=true + +# This is commented out, and the property is set conditionally in build.gradle, because 1.3.71 doesn't work with it. +# Once this property is set by default in new versions or 1.3.71 is dropped, either uncomment or remove this line. +#kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.mpp.enableCompatibilityMetadataVariant=true \ No newline at end of file diff --git a/gradle/publish-bintray.gradle b/gradle/publish-bintray.gradle index ee9337f8c8..b36c79763d 100644 --- a/gradle/publish-bintray.gradle +++ b/gradle/publish-bintray.gradle @@ -1,3 +1,5 @@ +import org.gradle.util.VersionNumber + /* * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ @@ -11,6 +13,7 @@ apply plugin: 'maven-publish' def isMultiplatform = project.name == "kotlinx-coroutines-core" def isBom = project.name == "kotlinx-coroutines-bom" +def isKotlin137x = VersionNumber.parse(kotlin_version) <= VersionNumber.parse("1.3.79") if (!isBom) { apply plugin: "com.github.johnrengelman.shadow" @@ -64,8 +67,8 @@ publishing { publications.all { MavenCentralKt.configureMavenCentralMetadata(pom, project) - // add empty javadocs (no need for MPP root publication which publishes only pom file) - if (it.name != 'kotlinMultiplatform' && !isBom) { + // add empty javadocs + if (!isBom && it.name != "kotlinMultiplatform") { it.artifact(javadocJar) } @@ -73,27 +76,42 @@ publishing { def type = it.name switch (type) { case 'kotlinMultiplatform': - it.artifactId = "$project.name-native" + // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with + // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too + it.artifactId = isKotlin137x ? "$project.name-native" : project.name + if (!isKotlin137x) { + apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle" + publishPlatformArtifactsInRootModule(publications["jvm"]) + } break case 'metadata': - it.artifactId = "$project.name-common" + // As the old -common dependencies will fail to resolve with Gradle module metadata, rename the module + // to '*-metadata' so that the resolution failure are more clear + it.artifactId = isKotlin137x ? "$project.name-common" : "$project.name-metadata" break case 'jvm': - it.artifactId = "$project.name" + it.artifactId = isKotlin137x ? project.name : "$project.name-jvm" break case 'js': case 'native': it.artifactId = "$project.name-$type" break } - - // disable metadata everywhere, but in native and js modules - if (type == 'maven' || type == 'metadata' || type == 'jvm') { - moduleDescriptorGenerator = null + // Hierarchical project structures are not fully supported in 1.3.7x MPP + if (isKotlin137x) { + // disable metadata everywhere, but in native and js modules + if (type == 'maven' || type == 'metadata' || type == 'jvm') { + moduleDescriptorGenerator = null + } } + } } +tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { + dependsOn(tasks["generatePomFileForJvmPublication"]) +} + task publishDevelopSnapshot() { def branch = System.getenv('currentBranch') if (branch == "develop") { diff --git a/gradle/publish-mpp-root-module-in-platform.gradle b/gradle/publish-mpp-root-module-in-platform.gradle new file mode 100644 index 0000000000..8bc0b502db --- /dev/null +++ b/gradle/publish-mpp-root-module-in-platform.gradle @@ -0,0 +1,39 @@ +/* + * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + + +/* + * Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module metadata + * can still get the platform artifact and transitive dependencies from the POM. + * + * See the full rationale here https://youtrack.jetbrains.com/issue/KMM-237#focus=streamItem-27-4115233.0-0 + */ +project.ext.publishPlatformArtifactsInRootModule = { platformPublication -> + def platformPomBuilder = null + + platformPublication.pom.withXml { platformPomBuilder = asString() } + + publishing.publications.kotlinMultiplatform { + platformPublication.artifacts.forEach { + artifact(it) + } + + pom.withXml { + def pomStringBuilder = asString() + pomStringBuilder.setLength(0) + // The platform POM needs its artifact ID replaced with the artifact ID of the root module: + def platformPomString = platformPomBuilder.toString() + platformPomString.eachLine { line -> + if (!line.contains("