Skip to content

Commit a484cad

Browse files
committed
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.
1 parent 64044ad commit a484cad

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

gradle/publish-bintray.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,24 @@ publishing {
6464
publications.all {
6565
MavenCentralKt.configureMavenCentralMetadata(pom, project)
6666

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

7272
// Rename MPP artifacts for backward compatibility
7373
def type = it.name
7474
switch (type) {
7575
case 'kotlinMultiplatform':
76-
it.artifactId = "$project.name-native"
76+
it.artifactId = "$project.name"
77+
apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
78+
publishPlatformArtifactsInRootModule(publications["jvm"])
7779
break
7880
case 'metadata':
7981
it.artifactId = "$project.name-common"
8082
break
8183
case 'jvm':
82-
it.artifactId = "$project.name"
84+
it.artifactId = "$project.name-jvm"
8385
break
8486
case 'js':
8587
case 'native':
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
/** Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module
7+
metadata can still get the platform artifact and transitive dependencies from the POM: */
8+
project.ext.publishPlatformArtifactsInRootModule = { platformPublication ->
9+
def platformPomBuilder = null
10+
11+
platformPublication.pom.withXml { platformPomBuilder = asString() }
12+
13+
publishing.publications.kotlinMultiplatform {
14+
platformPublication.artifacts.forEach {
15+
artifact(it)
16+
}
17+
18+
pom.withXml {
19+
def pomStringBuilder = asString()
20+
pomStringBuilder.setLength(0)
21+
// The platform POM needs its artifact ID replaced with the artifact ID of the root module:
22+
def platformPomString = platformPomBuilder.toString()
23+
platformPomString.eachLine { line ->
24+
if (!line.contains("<!--")) { // Remove the Gradle module metadata marker as it will be added anew
25+
pomStringBuilder.append(line.replace(platformPublication.artifactId, artifactId))
26+
pomStringBuilder.append("\n")
27+
}
28+
}
29+
}
30+
}
31+
32+
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
33+
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
34+
}
35+
}

0 commit comments

Comments
 (0)