From c5ce32653d89708470b700706011f46b4a9d86f3 Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Thu, 24 Jan 2019 21:47:08 +0300 Subject: [PATCH] Fix POM not rewritten correctly with custom artifact IDs (KT-29485) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the plugin rewrites a POM, it establishes the mapping of the original Maven coordinates to the modified ones. As one of the steps, this requires finding the original Maven coordinates to rewrite – these should be exactly the coordinates that Gradle writes to the POM. In MPP, these are the coordinates of the 'root' (Gradle module metadata) publication. If those are modified in the publication, the plugin relies on delegating to the publication in the root module's SotwareComponent (the only reasonable fallback is the project's name, and in this case it obviously doesn't match the Maven artifact ID that was modified). In 1.3.20, the publication delegate was never assigned. To fix the issue, it is enough to correctly assign the publication delegate for the root module's SoftwareComponent. Issue #KT-29485 Fixed --- .../kotlin/gradle/NewMultiplatformIT.kt | 23 ++++++++++++++++--- .../plugin/mpp/KotlinMultiplatformPlugin.kt | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 9b4820d1941..c2dcd30077f 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -1201,7 +1201,8 @@ class NewMultiplatformIT : BaseGradleIT() { ) } - gradleBuildScript().appendText("\n" + """ + gradleBuildScript().appendText( + "\n" + """ publishing { publications { jvm6 { @@ -1211,7 +1212,23 @@ class NewMultiplatformIT : BaseGradleIT() { } } } - """.trimIndent()) + """.trimIndent() + ) + + if (withMetadata) { + gradleBuildScript().appendText( + "\n" + """ + publishing { + publications { + kotlinMultiplatform { + // KT-29485 + artifactId = 'sample-lib-multiplatform' + } + } + } + """.trimIndent() + ) + } build("clean", "publish") { assertSuccessful() @@ -1240,7 +1257,7 @@ class NewMultiplatformIT : BaseGradleIT() { // Check that, despite the rewritten POM, the module metadata contains the original dependency: val moduleMetadata = projectDir.resolve("repo/com/exampleapp/sample-app-jvm8/1.0/sample-app-jvm8-1.0.module").readText() .replace("\\s+".toRegex(), "").replace("\n", "") - assertTrue { "\"group\":\"com.example\",\"module\":\"sample-lib\"" in moduleMetadata } + assertTrue { "\"group\":\"com.example\",\"module\":\"sample-lib-multiplatform\"" in moduleMetadata } assertTrue { "\"group\":\"com.external.dependency\",\"module\":\"external\"" in moduleMetadata } } assertFileExists("repo/foo/bar/42/bar-42.jar") diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt index 7515b85a2de..b9d05ce8502 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt @@ -171,6 +171,7 @@ class KotlinMultiplatformPlugin( val rootPublication = publishing.publications.create("kotlinMultiplatform", MavenPublication::class.java).apply { from(kotlinSoftwareComponent) (this as MavenPublicationInternal).publishWithOriginalFileName() + kotlinSoftwareComponent.publicationDelegate = this@apply } // Publish the root publication only if Gradle metadata publishing is enabled: