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 8e611251eb..683e93aa48 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("