Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 1 | /* |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 2 | * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 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 |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 14 | |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 15 | platformPublication.pom.withXml { platformPomBuilder = asString() } |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 16 | |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 17 | publishing.publications.kotlinMultiplatform { |
| 18 | platformPublication.artifacts.forEach { |
| 19 | artifact(it) |
| 20 | } |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 21 | |
| 22 | pom.withXml { |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 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 | } |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 36 | tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 37 | dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) |
| 38 | } |
Aurimas Liutikas | e64dad7 | 2021-05-12 21:56:16 +0000 | [diff] [blame] | 39 | } |