Add a switch that disables dependencies rewriting in POMs

This covers the cases when a user knows what they do and doesn't want
anything to do any changes to the POMs, e.g. they want to manually
replace all of the dependencies, so they need the original dependencies.
This commit is contained in:
Sergey Igushkin
2019-02-14 18:33:49 +03:00
parent 2f8baf6715
commit 51279a8195
3 changed files with 41 additions and 5 deletions
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.HostManager
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import java.io.File
import java.lang.StringBuilder import java.lang.StringBuilder
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.zip.ZipFile import java.util.zip.ZipFile
@@ -1272,8 +1273,6 @@ class NewMultiplatformIT : BaseGradleIT() {
"<version>42</version>" "<version>42</version>"
) )
if (withMetadata) { if (withMetadata) {
// Check that the external dependency that was resolved with metadata is written to the POM as the artifactId it
// resolved to:
assertFileContains( assertFileContains(
"repo/com/exampleapp/sample-app-jvm8/1.0/sample-app-jvm8-1.0.pom", "repo/com/exampleapp/sample-app-jvm8/1.0/sample-app-jvm8-1.0.pom",
"<groupId>com.external.dependency</groupId>", "<groupId>com.external.dependency</groupId>",
@@ -1287,7 +1286,39 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTrue { "\"group\":\"com.example\",\"module\":\"sample-lib-multiplatform\"" in moduleMetadata } assertTrue { "\"group\":\"com.example\",\"module\":\"sample-lib-multiplatform\"" in moduleMetadata }
assertTrue { "\"group\":\"com.external.dependency\",\"module\":\"external\"" in moduleMetadata } assertTrue { "\"group\":\"com.external.dependency\",\"module\":\"external\"" in moduleMetadata }
} }
assertFileExists("repo/foo/bar/42/bar-42.jar") }
// Check that a user can disable rewriting of MPP dependencies in the POMs:
build("publish", "-Pkotlin.mpp.keepMppDependenciesIntactInPoms=true") {
assertSuccessful()
assertFileContains(
"repo/com/exampleapp/sample-app-nodejs/1.0/sample-app-nodejs-1.0.pom",
"<groupId>com.example</groupId>",
if (withMetadata)
"<artifactId>sample-lib-multiplatform</artifactId>"
else
"<artifactId>sample-lib</artifactId>"
,
"<version>1.0</version>"
)
assertFileContains(
"repo/com/exampleapp/sample-app-jvm8/1.0/sample-app-jvm8-1.0.pom",
"<groupId>com.example</groupId>",
if (withMetadata)
"<artifactId>sample-lib-multiplatform</artifactId>"
else
"<artifactId>sample-lib</artifactId>"
,
"<version>1.0</version>"
)
if (withMetadata) {
assertFileContains(
"repo/com/exampleapp/sample-app-jvm8/1.0/sample-app-jvm8-1.0.pom",
"<groupId>com.external.dependency</groupId>",
"<artifactId>external</artifactId>",
"<version>1.2.3</version>"
)
}
} }
} }
} }
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.report.BuildReportMode
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -80,6 +79,9 @@ internal class PropertiesProvider(private val project: Project) {
val useFallbackCompilerSearch: Boolean? val useFallbackCompilerSearch: Boolean?
get() = booleanProperty("kotlin.useFallbackCompilerSearch") get() = booleanProperty("kotlin.useFallbackCompilerSearch")
val keepMppDependenciesIntactInPoms: Boolean?
get() = booleanProperty("kotlin.mpp.keepMppDependenciesIntactInPoms")
/** /**
* Enables parallel tasks execution within a project with Workers API. * Enables parallel tasks execution within a project with Workers API.
* Does not enable using actual worker proccesses * Does not enable using actual worker proccesses
@@ -205,7 +205,10 @@ class KotlinMultiplatformPlugin(
(this as MavenPublicationInternal).publishWithOriginalFileName() (this as MavenPublicationInternal).publishWithOriginalFileName()
artifactId = variant.defaultArtifactId artifactId = variant.defaultArtifactId
pom.withXml { xml -> project.rewritePomMppDependenciesToActualTargetModules(xml, variant) } pom.withXml { xml ->
if (PropertiesProvider(project).keepMppDependenciesIntactInPoms != true)
project.rewritePomMppDependenciesToActualTargetModules(xml, variant)
}
} }
(variant as? KotlinTargetComponentWithPublication)?.publicationDelegate = variantPublication (variant as? KotlinTargetComponentWithPublication)?.publicationDelegate = variantPublication