From d6a44c92b57831733597deb1666af44f961e23dc Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 16 Jan 2023 15:13:51 +0100 Subject: [PATCH] [Gradle] Implement KT55929MetadataConfigurationsTest to cover KT-55929 ^KT-55929 Verification Pending --- .../gradle/plugin/PropertiesProvider.kt | 4 +- .../KT55929MetadataConfigurationsTest.kt | 113 ++++++++++++++++++ .../kotlin/gradle/util/buildProject.kt | 7 +- 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55929MetadataConfigurationsTest.kt diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt index 56e882edcf3..57720b84fa8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_PLATFORM_INTEGER_COMMONIZATION import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT @@ -391,7 +392,7 @@ internal class PropertiesProvider private constructor(private val project: Proje get() = booleanProperty("kotlin.mpp.enableNativeDistributionCommonizationCache") ?: true val enableIntransitiveMetadataConfiguration: Boolean - get() = booleanProperty("kotlin.mpp.enableIntransitiveMetadataConfiguration") ?: false + get() = booleanProperty(KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION) ?: false val enableSlowIdeSourcesJarResolver: Boolean get() = booleanProperty(KOTLIN_MPP_IMPORT_ENABLE_SLOW_SOURCES_JAR_RESOLVER) ?: true @@ -550,6 +551,7 @@ internal class PropertiesProvider private constructor(private val project: Proje const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN = "${KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION}1.nowarn" const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN = "kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn" const val KOTLIN_MPP_IMPORT_ENABLE_SLOW_SOURCES_JAR_RESOLVER = "kotlin.mpp.import.enableSlowSourcesJarResolver" + const val KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION = "kotlin.mpp.enableIntransitiveMetadataConfiguration" const val KOTLIN_NATIVE_DEPENDENCY_PROPAGATION = "kotlin.native.enableDependencyPropagation" const val KOTLIN_NATIVE_CACHE_ORCHESTRATION = "kotlin.native.cacheOrchestration" const val KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION = "kotlin.mpp.enableOptimisticNumberCommonization" diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55929MetadataConfigurationsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55929MetadataConfigurationsTest.kt new file mode 100644 index 00000000000..88427911453 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55929MetadataConfigurationsTest.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2010-2023 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. + */ + +@file:Suppress("FunctionName") + +package org.jetbrains.kotlin.gradle.regressionTests + +import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet +import org.jetbrains.kotlin.gradle.util.* +import org.junit.Test + +@Suppress("DEPRECATION") /* Configurations are scheduled for removal */ +class KT55929MetadataConfigurationsTest { + + @Test + fun `test - deprecated metadata configurations - contain dependencies from common source set`() { + val project = buildProject { + enableDefaultStdlibDependency(false) + enableIntransitiveMetadataConfiguration(true) + applyMultiplatformPlugin() + } + + val kotlin = project.multiplatformExtension + + kotlin.jvm() + kotlin.linuxX64() + kotlin.linuxArm64() + + kotlin.targetHierarchy.default { + common { + group("jvmAndLinux") { + addCompilations { it.platformType == KotlinPlatformType.jvm } + anyLinux() + group("linux") + } + } + } + + val commonMain = kotlin.sourceSets.getByName("commonMain") + val jvmAndLinuxMain = kotlin.sourceSets.getByName("jvmAndLinuxMain") + val linuxMain = kotlin.sourceSets.getByName("linuxMain") + + commonMain.dependencies { + api("org.sample:commonMainApi:1.0.0") + implementation("org.sample:commonMainImplementation:1.0.0") + } + + jvmAndLinuxMain.dependencies { + implementation("org.sample:jvmAndLinuxMain:1.0.0") + } + + linuxMain.dependencies { + implementation("org.sample:linuxMain:1.0.0") + } + + project.evaluate() + + /* Check linuxMain */ + listOf( + linuxMain.apiMetadataConfigurationName, + linuxMain.implementationMetadataConfigurationName, + linuxMain.compileOnlyMetadataConfigurationName + ).forEach { metadataConfigurationName -> + project.assertContainsDependencies( + metadataConfigurationName, + "org.sample:commonMainApi:1.0.0", + "org.sample:commonMainImplementation:1.0.0", + "org.sample:jvmAndLinuxMain:1.0.0", + "org.sample:linuxMain:1.0.0", + ) + } + + /* Check jvmAndLinuxMain */ + listOf( + jvmAndLinuxMain.apiMetadataConfigurationName, + jvmAndLinuxMain.implementationMetadataConfigurationName, + jvmAndLinuxMain.compileOnlyMetadataConfigurationName + ).forEach { metadataConfigurationName -> + project.assertContainsDependencies( + metadataConfigurationName, + "org.sample:commonMainApi:1.0.0", + "org.sample:commonMainImplementation:1.0.0", + "org.sample:jvmAndLinuxMain:1.0.0", + ) + } + + /* Check commonMain */ + listOf( + jvmAndLinuxMain.apiMetadataConfigurationName, + jvmAndLinuxMain.implementationMetadataConfigurationName, + jvmAndLinuxMain.compileOnlyMetadataConfigurationName + ).forEach { metadataConfigurationName -> + project.assertContainsDependencies( + metadataConfigurationName, + "org.sample:commonMainApi:1.0.0", + "org.sample:commonMainImplementation:1.0.0", + ) + } + + /* Check intransitive configurations */ + kotlin.sourceSets.forEach { sourceSet -> + sourceSet as DefaultKotlinSourceSet + project.assertNotContainsDependencies( + sourceSet.intransitiveMetadataConfigurationName, + "org.sample:commonMainApi:1.0.0" + ) + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt index 6fd47fe710f..8cc31c5f9ea 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt @@ -14,11 +14,12 @@ import org.gradle.api.plugins.ExtraPropertiesExtension import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension -import org.jetbrains.kotlin.gradle.unitTests.kpm.applyKpmPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinPm20ProjectExtension +import org.jetbrains.kotlin.gradle.unitTests.kpm.applyKpmPlugin fun buildProject( projectBuilder: ProjectBuilder.() -> Unit = { }, @@ -100,6 +101,10 @@ fun Project.enableHierarchicalStructureByDefault(enabled: Boolean = true) { propertiesExtension.set(PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT, enabled.toString()) } +fun Project.enableIntransitiveMetadataConfiguration(enabled: Boolean = true) { + propertiesExtension.set(KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION, enabled.toString()) +} + fun Project.enableDefaultStdlibDependency(enabled: Boolean = true) { project.propertiesExtension.set(PropertiesProvider.PropertyNames.KOTLIN_STDLIB_DEFAULT_DEPENDENCY, enabled.toString()) }