blob: 8bc0b502db0ea5cc243cfabbb716b28db22a34a1 [file] [log] [blame]
Sergey Igushkin17248c82020-05-22 12:28:25 +03001/*
Aurimas Liutikase64dad72021-05-12 21:56:16 +00002 * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
Sergey Igushkin17248c82020-05-22 12:28:25 +03003 */
4
5
Aurimas Liutikase64dad72021-05-12 21:56:16 +00006/*
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 */
12project.ext.publishPlatformArtifactsInRootModule = { platformPublication ->
13 def platformPomBuilder = null
Sergey Igushkin17248c82020-05-22 12:28:25 +030014
Aurimas Liutikase64dad72021-05-12 21:56:16 +000015 platformPublication.pom.withXml { platformPomBuilder = asString() }
Sergey Igushkin17248c82020-05-22 12:28:25 +030016
Aurimas Liutikase64dad72021-05-12 21:56:16 +000017 publishing.publications.kotlinMultiplatform {
18 platformPublication.artifacts.forEach {
19 artifact(it)
20 }
Sergey Igushkin17248c82020-05-22 12:28:25 +030021
22 pom.withXml {
Aurimas Liutikase64dad72021-05-12 21:56:16 +000023 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 }
Sergey Igushkin17248c82020-05-22 12:28:25 +030033 }
34 }
35
Aurimas Liutikase64dad72021-05-12 21:56:16 +000036 tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
Sergey Igushkin17248c82020-05-22 12:28:25 +030037 dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
38 }
Aurimas Liutikase64dad72021-05-12 21:56:16 +000039}