• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: */
8project.ext.publishPlatformArtifactsInRootModule = { platformPublication ->
9    afterEvaluate {
10        def platformPomBuilder = null
11
12        platformPublication.pom.withXml { platformPomBuilder = asString() }
13
14        publishing.publications.kotlinMultiplatform {
15            platformPublication.artifacts.forEach {
16                artifact(it)
17            }
18
19            pom.withXml {
20                def pomStringBuilder = asString()
21                pomStringBuilder.setLength(0)
22                // The platform POM needs its artifact ID replaced with the artifact ID of the root module:
23                def platformPomString = platformPomBuilder.toString()
24                platformPomString.eachLine { line ->
25                    if (!line.contains("<!--")) { // Remove the Gradle module metadata marker as it will be added anew
26                        pomStringBuilder.append(line.replace(platformPublication.artifactId, artifactId))
27                        pomStringBuilder.append("\n")
28                    }
29                }
30            }
31        }
32
33        tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
34            dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
35        }
36    }
37}