From 1deb1161dacdb36cf9e3734f3edf7d49913f5fb5 Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Fri, 23 Feb 2024 08:42:25 +0100 Subject: [PATCH] [Gradle] Compare resolved components ignoring versions for source sets Source Set Visibility algorithm relies on the match between metadata dependencies resolution and platform dependencies resolution. However there is a chance that they don't match in versions. i.e. commonMain resolved into 1.0 but jvmMain got 2.0 of the same library. However this discrepancy is not correct after all. And both metadata compilations and platform compilations should see the same set of libraries. This behavior will be fixed in KT-66047 ^KT-65954 Verification Pending --- .../plugin/mpp/SourceSetVisibilityProvider.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/SourceSetVisibilityProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/SourceSetVisibilityProvider.kt index e9baf9877ece9..6fe1d8812a264 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/SourceSetVisibilityProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/SourceSetVisibilityProvider.kt @@ -6,6 +6,9 @@ package org.jetbrains.kotlin.gradle.plugin.mpp import org.gradle.api.Project +import org.gradle.api.artifacts.component.ComponentIdentifier +import org.gradle.api.artifacts.component.ModuleComponentIdentifier +import org.gradle.api.artifacts.component.ProjectComponentIdentifier import org.gradle.api.artifacts.result.ResolvedDependencyResult import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation @@ -94,7 +97,7 @@ internal class SourceSetVisibilityProvider( val resolvedPlatformDependency = platformCompilationData .resolvedDependenciesConfiguration .allResolvedDependencies - .find { it.selected.id == resolvedRootMppDependencyId } + .find { it.selected.id isEqualsIgnoringVersion resolvedRootMppDependencyId } /* Returning null if we can't find the given dependency in a certain platform compilations dependencies. This is not expected, since this means the dependency does not support the given targets which will @@ -188,3 +191,13 @@ internal class SourceSetVisibilityProvider( internal fun kotlinVariantNameFromPublishedVariantName(resolvedToVariantName: String): String = originalVariantNameFromPublished(resolvedToVariantName) ?: resolvedToVariantName + +/** + * Returns true when two components identifiers are from the same maven module (group + name) + * Gradle projects can't be resolved into multiple versions since there is only one version of a project in gradle build + */ +private infix fun ComponentIdentifier.isEqualsIgnoringVersion(that: ComponentIdentifier): Boolean { + if (this is ProjectComponentIdentifier && that is ProjectComponentIdentifier) return this == that + if (this is ModuleComponentIdentifier && that is ModuleComponentIdentifier) return this.moduleIdentifier == that.moduleIdentifier + return false +}