Skip to content

Commit b3a7b59

Browse files
h0tk3ydsavvinovqwwdfsad
authored andcommitted
Fixes for 1.4-M2 & HMPP (Kotlin#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 <[email protected]> Co-authored-by: Vsevolod Tolstopyatov <[email protected]>
1 parent 9128a9b commit b3a7b59

File tree

7 files changed

+102
-14
lines changed

7 files changed

+102
-14
lines changed

build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44
import org.jetbrains.kotlin.konan.target.HostManager
5+
import org.gradle.util.VersionNumber
56

67
apply plugin: 'jdk-convention'
78
apply from: rootProject.file("gradle/experimental.gradle")
@@ -79,6 +80,11 @@ buildscript {
7980

8081
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
8182

83+
// Hierarchical project structures are not fully supported in 1.3.7x MPP, enable conditionally for 1.4.x
84+
if (VersionNumber.parse(kotlin_version) > VersionNumber.parse("1.3.79")) {
85+
ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
86+
}
87+
8288
// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
8389
def configureKotlinJvmPlatform(configuration) {
8490
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
@@ -192,6 +198,8 @@ if (build_snapshot_train) {
192198
exclude '**/*definitely/not/kotlinx*'
193199
// Disable because of KT-11567 in 1.4
194200
exclude '**/*CasesPublicAPITest*'
201+
// Kotlin
202+
exclude '**/*PrecompiledDebugProbesTest*'
195203
}
196204
}
197205

gradle.properties

+9
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ jekyll_version=4.0
5151
# JS IR baceknd sometimes crashes with out-of-memory
5252
# TODO: Remove once KT-37187 is fixed
5353
org.gradle.jvmargs=-Xmx2g
54+
55+
# Workaround for Bintray treating .sha512 files as artifacts
56+
# https://github.com/gradle/gradle/issues/11412
57+
systemProp.org.gradle.internal.publish.checksums.insecure=true
58+
59+
# This is commented out, and the property is set conditionally in build.gradle, because 1.3.71 doesn't work with it.
60+
# Once this property is set by default in new versions or 1.3.71 is dropped, either uncomment or remove this line.
61+
#kotlin.mpp.enableGranularSourceSetsMetadata=true
62+
kotlin.mpp.enableCompatibilityMetadataVariant=true

gradle/publish-bintray.gradle

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.util.VersionNumber
2+
13
/*
24
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
35
*/
@@ -11,6 +13,7 @@ apply plugin: 'maven-publish'
1113

1214
def isMultiplatform = project.name == "kotlinx-coroutines-core"
1315
def isBom = project.name == "kotlinx-coroutines-bom"
16+
def isKotlin137x = VersionNumber.parse(kotlin_version) <= VersionNumber.parse("1.3.79")
1417

1518
if (!isBom) {
1619
apply plugin: "com.github.johnrengelman.shadow"
@@ -64,36 +67,51 @@ publishing {
6467
publications.all {
6568
MavenCentralKt.configureMavenCentralMetadata(pom, project)
6669

67-
// add empty javadocs (no need for MPP root publication which publishes only pom file)
68-
if (it.name != 'kotlinMultiplatform' && !isBom) {
70+
// add empty javadocs
71+
if (!isBom && it.name != "kotlinMultiplatform") {
6972
it.artifact(javadocJar)
7073
}
7174

7275
// Rename MPP artifacts for backward compatibility
7376
def type = it.name
7477
switch (type) {
7578
case 'kotlinMultiplatform':
76-
it.artifactId = "$project.name-native"
79+
// With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with
80+
// the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too
81+
it.artifactId = isKotlin137x ? "$project.name-native" : project.name
82+
if (!isKotlin137x) {
83+
apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
84+
publishPlatformArtifactsInRootModule(publications["jvm"])
85+
}
7786
break
7887
case 'metadata':
79-
it.artifactId = "$project.name-common"
88+
// As the old -common dependencies will fail to resolve with Gradle module metadata, rename the module
89+
// to '*-metadata' so that the resolution failure are more clear
90+
it.artifactId = isKotlin137x ? "$project.name-common" : "$project.name-metadata"
8091
break
8192
case 'jvm':
82-
it.artifactId = "$project.name"
93+
it.artifactId = isKotlin137x ? project.name : "$project.name-jvm"
8394
break
8495
case 'js':
8596
case 'native':
8697
it.artifactId = "$project.name-$type"
8798
break
8899
}
89-
90-
// disable metadata everywhere, but in native and js modules
91-
if (type == 'maven' || type == 'metadata' || type == 'jvm') {
92-
moduleDescriptorGenerator = null
100+
// Hierarchical project structures are not fully supported in 1.3.7x MPP
101+
if (isKotlin137x) {
102+
// disable metadata everywhere, but in native and js modules
103+
if (type == 'maven' || type == 'metadata' || type == 'jvm') {
104+
moduleDescriptorGenerator = null
105+
}
93106
}
107+
94108
}
95109
}
96110

111+
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
112+
dependsOn(tasks["generatePomFileForJvmPublication"])
113+
}
114+
97115
task publishDevelopSnapshot() {
98116
def branch = System.getenv('currentBranch')
99117
if (branch == "develop") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
6+
/*
7+
* Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module metadata
8+
* can still get the platform artifact and transitive dependencies from the POM.
9+
*
10+
* See the full rationale here https://youtrack.jetbrains.com/issue/KMM-237#focus=streamItem-27-4115233.0-0
11+
*/
12+
project.ext.publishPlatformArtifactsInRootModule = { platformPublication ->
13+
def platformPomBuilder = null
14+
15+
platformPublication.pom.withXml { platformPomBuilder = asString() }
16+
17+
publishing.publications.kotlinMultiplatform {
18+
platformPublication.artifacts.forEach {
19+
artifact(it)
20+
}
21+
22+
pom.withXml {
23+
def pomStringBuilder = asString()
24+
pomStringBuilder.setLength(0)
25+
// The platform POM needs its artifact ID replaced with the artifact ID of the root module:
26+
def platformPomString = platformPomBuilder.toString()
27+
platformPomString.eachLine { line ->
28+
if (!line.contains("<!--")) { // Remove the Gradle module metadata marker as it will be added anew
29+
pomStringBuilder.append(line.replace(platformPublication.artifactId, artifactId))
30+
pomStringBuilder.append("\n")
31+
}
32+
}
33+
}
34+
}
35+
36+
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
37+
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
38+
}
39+
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ distributionBase=GRADLE_USER_HOME
66
distributionPath=wrapper/dists
77
zipStoreBase=GRADLE_USER_HOME
88
zipStorePath=wrapper/dists
9-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
9+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

integration-testing/build.gradle

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
2+
13
/*
24
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
35
*/
@@ -56,14 +58,19 @@ task npmTest(type: Test) {
5658
task mavenTest(type: Test) {
5759
def sourceSet = sourceSets.mavenTest
5860
dependsOn(project(':').getTasksByName("publishToMavenLocal", true))
59-
dependsOn.remove(project(':').getTasksByName("dokka", true))
6061
testClassesDirs = sourceSet.output.classesDirs
6162
classpath = sourceSet.runtimeClasspath
6263
// we can't depend on the subprojects because we need to test the classfiles that are published in the end.
6364
// also, we can't put this in the `dependencies` block because the resolution would happen before publication.
64-
classpath += project.configurations.detachedConfiguration(
65+
def mavenTestClasspathConfiguration = project.configurations.detachedConfiguration(
6566
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"),
6667
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"))
68+
69+
mavenTestClasspathConfiguration.attributes {
70+
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
71+
}
72+
73+
classpath += mavenTestClasspathConfiguration
6774
}
6875

6976
task debugAgentTest(type: Test) {

kotlinx-coroutines-core/build.gradle

+9-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ kotlin.sourceSets {
6060
}
6161

6262
jvmTest.dependencies {
63-
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
63+
// This is a workaround for https://youtrack.jetbrains.com/issue/KT-39037
64+
def excludingCurrentProject = { dependency ->
65+
def result = project.dependencies.create(dependency)
66+
result.exclude(module: project.name)
67+
return result
68+
}
69+
70+
api(excludingCurrentProject("org.jetbrains.kotlinx:lincheck:$lincheck_version"))
6471
api "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version"
6572
api "com.esotericsoftware:kryo:4.0.0"
66-
implementation project (":android-unit-tests")
73+
implementation(excludingCurrentProject(project(":android-unit-tests")))
6774
}
6875
}
6976

0 commit comments

Comments
 (0)