Skip to content

Commit

Permalink
Fixes for 1.4-M2 & HMPP (#2031)
Browse files Browse the repository at this point in the history
* 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 <dmitry.savvinov@jetbrains.com>
Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
  • Loading branch information
3 people committed May 22, 2020
1 parent 1eeed50 commit 17248c8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 14 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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*'
}
}

Expand Down
9 changes: 9 additions & 0 deletions gradle.properties
Expand Up @@ -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
36 changes: 27 additions & 9 deletions 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.
*/
Expand All @@ -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"
Expand Down Expand Up @@ -64,36 +67,51 @@ 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)
}

// Rename MPP artifacts for backward compatibility
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") {
Expand Down
39 changes: 39 additions & 0 deletions 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("<!--")) { // Remove the Gradle module metadata marker as it will be added anew
pomStringBuilder.append(line.replace(platformPublication.artifactId, artifactId))
pomStringBuilder.append("\n")
}
}
}
}

tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -6,4 +6,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
11 changes: 9 additions & 2 deletions integration-testing/build.gradle
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand Down Expand Up @@ -56,14 +58,19 @@ task npmTest(type: Test) {
task mavenTest(type: Test) {
def sourceSet = sourceSets.mavenTest
dependsOn(project(':').getTasksByName("publishToMavenLocal", true))
dependsOn.remove(project(':').getTasksByName("dokka", true))
testClassesDirs = sourceSet.output.classesDirs
classpath = sourceSet.runtimeClasspath
// we can't depend on the subprojects because we need to test the classfiles that are published in the end.
// also, we can't put this in the `dependencies` block because the resolution would happen before publication.
classpath += project.configurations.detachedConfiguration(
def mavenTestClasspathConfiguration = project.configurations.detachedConfiguration(
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"),
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"))

mavenTestClasspathConfiguration.attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
}

classpath += mavenTestClasspathConfiguration
}

task debugAgentTest(type: Test) {
Expand Down
11 changes: 9 additions & 2 deletions kotlinx-coroutines-core/build.gradle
Expand Up @@ -60,10 +60,17 @@ kotlin.sourceSets {
}

jvmTest.dependencies {
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
// This is a workaround for https://youtrack.jetbrains.com/issue/KT-39037
def excludingCurrentProject = { dependency ->
def result = project.dependencies.create(dependency)
result.exclude(module: project.name)
return result
}

api(excludingCurrentProject("org.jetbrains.kotlinx:lincheck:$lincheck_version"))
api "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version"
api "com.esotericsoftware:kryo:4.0.0"
implementation project (":android-unit-tests")
implementation(excludingCurrentProject(project(":android-unit-tests")))
}
}

Expand Down

0 comments on commit 17248c8

Please sign in to comment.