From e87ea4c209e42d4e9b425f8644a14945623d5aa2 Mon Sep 17 00:00:00 2001 From: "Andrei.Tyrin" Date: Thu, 4 Aug 2022 18:25:50 +0200 Subject: [PATCH] [MPP] Support for `platform` notation in Gradle MPP dependencies configuration KT-53396 --- .../gradle/plugin/HasKotlinDependencies.kt | 6 +++ .../kotlin/gradle/ConfigurationsTest.kt | 44 +++++++++++++++++++ .../kotlin/gradle/EnforcedPlatformTest.kt | 36 --------------- 3 files changed, 50 insertions(+), 36 deletions(-) delete mode 100644 libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/EnforcedPlatformTest.kt diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt index 84b45275f6b..6cdbda5b96e 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt @@ -62,6 +62,12 @@ interface KotlinDependencyHandler { fun enforcedPlatform(notation: Any, configureAction: Action): Dependency = project.dependencies.enforcedPlatform(notation, configureAction) + fun platform(notation: Any): Dependency = + project.dependencies.platform(notation) + + fun platform(notation: Any, configureAction: Action): Dependency = + project.dependencies.platform(notation, configureAction) + @Deprecated("Declaring NPM dependency without version is forbidden") fun npm(name: String): Dependency diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt index a956335b094..df502b913de 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt @@ -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") + ) + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/EnforcedPlatformTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/EnforcedPlatformTest.kt deleted file mode 100644 index c8c27795a71..00000000000 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/EnforcedPlatformTest.kt +++ /dev/null @@ -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") - } - } -} \ No newline at end of file