/* * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ /** * Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module * metadata can still get the platform artifact and transitive dependencies from the POM * (see details in https://youtrack.jetbrains.com/issue/KT-39184#focus=streamItem-27-4115233.0-0) */ project.ext.publishPlatformArtifactsInRootModule = { MavenPublication platformPublication -> afterEvaluate { XmlProvider platformXml = null platformPublication.pom.withXml { platformXml = it } publishing.publications.kotlinMultiplatform { pom.withXml { Node root = asNode() // Remove the original content and add the content from the platform POM: root.children().toList().each { root.remove(it as Node) } platformXml.asNode().children().each { root.append(it as Node) } // Adjust the self artifact ID, as it should match the root module's coordinates: ((root.get("artifactId") as NodeList).get(0) as Node).setValue(artifactId) // Set packaging to POM to indicate that there's no artifact: root.appendNode("packaging", "pom") // Remove the original platform dependencies and add a single dependency on the platform module: Node dependencies = (root.get("dependencies") as NodeList).get(0) as Node dependencies.children().toList().each { dependencies.remove(it as Node) } Node singleDependency = dependencies.appendNode("dependency") singleDependency.appendNode("groupId", platformPublication.groupId) singleDependency.appendNode("artifactId", platformPublication.artifactId) singleDependency.appendNode("version", platformPublication.version) singleDependency.appendNode("scope", "compile") } } tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) } } }