• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2016-2021 JetBrains s.r.o. 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 = { MavenPublication platformPublication ->
9
10    XmlProvider platformXml = null
11
12    platformPublication.pom.withXml { platformXml = it }
13
14    publishing.publications.kotlinMultiplatform {
15        pom.withXml {
16            Node root = asNode()
17            // Remove the original content and add the content from the platform POM:
18            root.children().toList().each { root.remove(it as Node) }
19            platformXml.asNode().children().each { root.append(it as Node) }
20
21            // Adjust the self artifact ID, as it should match the root module's coordinates:
22            ((root.get("artifactId") as NodeList).get(0) as Node).setValue(artifactId)
23
24            // Set packaging to POM to indicate that there's no artifact:
25            root.appendNode("packaging", "pom")
26
27            // Remove the original platform dependencies and add a single dependency on the platform module:
28            Node dependencies = (root.get("dependencies") as NodeList).get(0) as Node
29            dependencies.children().toList().each { dependencies.remove(it as Node) }
30            Node singleDependency = dependencies.appendNode("dependency")
31            singleDependency.appendNode("groupId", platformPublication.groupId)
32            singleDependency.appendNode("artifactId", platformPublication.artifactId)
33            singleDependency.appendNode("version", platformPublication.version)
34            singleDependency.appendNode("scope", "compile")
35        }
36    }
37
38    tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach {
39        dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
40    }
41
42}
43