diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/resolvableMetadataConfiguration.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/resolvableMetadataConfiguration.kt index cc308ee966c..37f78dd9792 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/resolvableMetadataConfiguration.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/resolvableMetadataConfiguration.kt @@ -134,9 +134,5 @@ private fun Project.configureConsistentDependencyResolution(groupOfSourceSets: C configuration.extendsFrom(*extenders.toTypedArray()) groupOfSourceSets.forEach { it.internal.resolvableMetadataConfiguration.shouldResolveConsistentlyWith(configuration) } - // Make actual compilation classpaths/libraries configurations to have the same consistent dependencies - groupOfSourceSets - .flatMap { it.internal.compilations } - .toSet() - .forEach { project.configurations.getByName(it.compileDependencyConfigurationName).shouldResolveConsistentlyWith(configuration) } + // FIXME: KT-66375 Make actual compilation classpaths/libraries configurations to have the same consistent dependencies } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/ResolvableMetadataConfigurationTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/ResolvableMetadataConfigurationTest.kt index b8a37ebdb3f..d732a08a327 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/ResolvableMetadataConfigurationTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/ResolvableMetadataConfigurationTest.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.kotlinToolingVersion import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration import org.jetbrains.kotlin.gradle.plugin.sources.internal import org.jetbrains.kotlin.gradle.util.* +import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.fail @@ -115,6 +116,7 @@ class ResolvableMetadataConfigurationTest : SourceSetDependenciesResolution() { } @Test + @Ignore("TODO: KT-66375") fun jvmMainWithHigherVersion() { assertSourceSetDependenciesResolution("leafSourceSetWithHigherVersion.txt") { project -> project.defaultTargets() @@ -130,6 +132,7 @@ class ResolvableMetadataConfigurationTest : SourceSetDependenciesResolution() { } @Test + @Ignore("TODO: KT-66375") fun nativeMainWithHigherVersion() { assertSourceSetDependenciesResolution("leafSourceSetWithHigherVersion.txt") { project -> project.defaultTargets() @@ -142,6 +145,7 @@ class ResolvableMetadataConfigurationTest : SourceSetDependenciesResolution() { } @Test + @Ignore("TODO: KT-66375") fun jsMainWithHigherVersion() { assertSourceSetDependenciesResolution("leafSourceSetWithHigherVersion.txt") { project -> project.defaultTargets() @@ -167,6 +171,7 @@ class ResolvableMetadataConfigurationTest : SourceSetDependenciesResolution() { } @Test + @Ignore("TODO: KT-66375") fun leafSourceSetsDependsOnDifferentVersionsAndCommonCodeDoesNot() { assertSourceSetDependenciesResolution("leafSourceSetsDependsOnDifferentVersionsAndCommonCodeDoesNot.txt") { project -> project.defaultTargets() @@ -180,6 +185,31 @@ class ResolvableMetadataConfigurationTest : SourceSetDependenciesResolution() { } } + /** + * after KT-66375 is fixed it is expected that all source sets will have foo:2.0 dependency + * unless other is decided + */ + @Test + fun KT66375JvmDependenciesShouldNotDowngrade() { + val appProject = buildProject(projectBuilder = { withName("app") }) + val libProject = buildProject(projectBuilder = { withName("lib").withParent(appProject) }) + + assertSourceSetDependenciesResolution("KT66375JvmDependenciesShouldNotDowngrade.txt", withProject = appProject) { + appProject.applyMultiplatformPlugin().apply { + jvm(); linuxX64() + // common main depends on 1.0 + sourceSets.getByName("commonMain").dependencies { this.api(mockedDependency("foo", "1.0")) } + // jvm main depends on lib that transitively depends on 2.0 + sourceSets.jvmMain.dependencies { api(project(":lib")) } + } + + libProject.applyMultiplatformPlugin().apply { + jvm(); linuxX64() + sourceSets.jvmMain.dependencies { api(mockedDependency("foo", "2.0")) } + } + } + } + private fun Project.defaultTargets() { kotlin { jvm(); linuxX64(); js(); applyDefaultHierarchyTemplate() } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/SourceSetDependenciesResolution.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/SourceSetDependenciesResolution.kt index 091b50f805d..dd9e255ff04 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/SourceSetDependenciesResolution.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/dependencyResolutionTests/SourceSetDependenciesResolution.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.gradle.dependencyResolutionTests import org.gradle.api.Project +import org.gradle.api.internal.project.ProjectInternal import org.gradle.kotlin.dsl.maven import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension @@ -29,20 +30,36 @@ abstract class SourceSetDependenciesResolution { /** * Declares an API dependency to test:[name]:[version] for [sourceSetName] source set */ - fun api(sourceSetName: String, name: String, version: String) { + fun api(sourceSetName: String, name: String, version: String): Unit = project + .kotlinExtension + .sourceSets + .getByName(sourceSetName) + .dependencies { api(mockedDependency(name, version)) } + + fun mockedDependency(name: String, version: String): String { declaredDependencies.add(name to version) - project.kotlinExtension.sourceSets.getByName(sourceSetName).dependencies { api("test:$name:$version") } + return "test:$name:$version" } } - fun assertSourceSetDependenciesResolution(expectedFilePath: String, configure: SourceSetDependenciesDsl.(Project) -> Unit) { + /** + * If [withProject] is not null then dependencies of source sets in this projects will be verified against [expectedFilePath] + * + */ + fun assertSourceSetDependenciesResolution( + expectedFilePath: String, + withProject: ProjectInternal? = null, + configure: SourceSetDependenciesDsl.(Project) -> Unit + ) { val repoRoot = tempFolder.newFolder() - val project = buildProject { - enableDefaultStdlibDependency(false) - enableDependencyVerification(false) + val project = withProject ?: buildProject { applyMultiplatformPlugin() + } - repositories.maven(repoRoot) + project.allprojects { + it.enableDefaultStdlibDependency(false) + it.enableDependencyVerification(false) + it.repositories.maven(repoRoot) } val dsl = SourceSetDependenciesDsl(project) diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/resources/dependenciesResolution/KT66375JvmDependenciesShouldNotDowngrade.txt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/resources/dependenciesResolution/KT66375JvmDependenciesShouldNotDowngrade.txt new file mode 100644 index 00000000000..2452ba24954 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/resources/dependenciesResolution/KT66375JvmDependenciesShouldNotDowngrade.txt @@ -0,0 +1,22 @@ +commonMain + test:foo:1.0 +commonTest + test:foo:1.0 +jvmMain + project :lib + test:foo:2.0 +jvmTest + project :lib + test:foo:2.0 +linuxMain + test:foo:1.0 +linuxTest + test:foo:1.0 +linuxX64Main + test:foo:1.0 +linuxX64Test + test:foo:1.0 +nativeMain + test:foo:1.0 +nativeTest + test:foo:1.0