[MPP] Support for platform notation in Gradle MPP dependencies configuration

KT-53396
This commit is contained in:
Andrei.Tyrin
2022-08-04 18:25:50 +02:00
committed by teamcity
parent ec8da2033c
commit e87ea4c209
3 changed files with 50 additions and 36 deletions
@@ -62,6 +62,12 @@ interface KotlinDependencyHandler {
fun enforcedPlatform(notation: Any, configureAction: Action<in Dependency>): Dependency =
project.dependencies.enforcedPlatform(notation, configureAction)
fun platform(notation: Any): Dependency =
project.dependencies.platform(notation)
fun platform(notation: Any, configureAction: Action<in Dependency>): Dependency =
project.dependencies.platform(notation, configureAction)
@Deprecated("Declaring NPM dependency without version is forbidden")
fun npm(name: String): Dependency
@@ -326,4 +326,48 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
}
}
}
@Test
fun `test platform notation for BOM is consumable in dependencies`() {
val project = buildProjectWithMPP {
kotlin {
jvm()
sourceSets.getByName("jvmMain").apply {
dependencies {
api(platform("test:platform-dependency:1.0.0"))
}
}
}
}
project.evaluate()
project.assertContainsDependencies("jvmMainApi", project.dependencies.platform("test:platform-dependency:1.0.0"))
}
@Test
fun `test enforcedPlatform notation for BOM is consumable in dependencies`() {
val project = buildProjectWithMPP {
kotlin {
js("browser") {
browser {
binaries.executable()
}
}
sourceSets.getByName("browserMain").apply {
dependencies {
implementation(enforcedPlatform("test:enforced-platform-dependency"))
}
}
}
}
project.evaluate()
project.assertContainsDependencies(
"browserMainImplementation",
project.dependencies.enforcedPlatform("test:enforced-platform-dependency")
)
}
}
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle
import kotlin.test.Test
import kotlin.test.assertTrue
class EnforcedPlatformTest : MultiplatformExtensionTest() {
@Test
fun `using enforcedPlatform adds BOM dependency correctly`() {
val project = buildProjectWithMPP {
kotlin {
js("browser") {
browser {
binaries.executable()
}
}
sourceSets.getByName("browserMain").apply {
dependencies {
implementation(enforcedPlatform("test:enforced-platform-dependency"))
}
}
}
}
with(project.evaluate()) {
val hasEnforcedPlatformDependency = configurations.getByName("browserMainImplementation").allDependencies.any {
it.group == "test" && it.name == "enforced-platform-dependency" && it.version == null
}
assertTrue(hasEnforcedPlatformDependency, "Could not find enforced platform dependency")
}
}
}