blob: 38b7f89c238301c525327d273a32e639a3cf772c [file] [log] [blame]
/*
* 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: */
project.ext.publishPlatformArtifactsInRootModule = { platformPublication ->
afterEvaluate {
def platformPomBuilder = null
platformPublication.pom.withXml { platformPomBuilder = asString() }
publishing.publications.kotlinMultiplatform {
platformPublication.artifacts.forEach {
artifact(it)
}
pom.withXml {
def pomStringBuilder = asString()
pomStringBuilder.setLength(0)
// The platform POM needs its artifact ID replaced with the artifact ID of the root module:
def platformPomString = platformPomBuilder.toString()
platformPomString.eachLine { line ->
if (!line.contains("<!--")) { // Remove the Gradle module metadata marker as it will be added anew
pomStringBuilder.append(line.replace(platformPublication.artifactId, artifactId))
pomStringBuilder.append("\n")
}
}
}
}
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
}
}
}