Skip to content

Commit 1deb116

Browse files
antohabySpace Team
authored and
Space Team
committed
[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
1 parent 1b11027 commit 1deb116

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/SourceSetVisibilityProvider.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
package org.jetbrains.kotlin.gradle.plugin.mpp
77

88
import org.gradle.api.Project
9+
import org.gradle.api.artifacts.component.ComponentIdentifier
10+
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
11+
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
912
import org.gradle.api.artifacts.result.ResolvedDependencyResult
1013
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
1114
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
@@ -94,7 +97,7 @@ internal class SourceSetVisibilityProvider(
9497
val resolvedPlatformDependency = platformCompilationData
9598
.resolvedDependenciesConfiguration
9699
.allResolvedDependencies
97-
.find { it.selected.id == resolvedRootMppDependencyId }
100+
.find { it.selected.id isEqualsIgnoringVersion resolvedRootMppDependencyId }
98101
/*
99102
Returning null if we can't find the given dependency in a certain platform compilations dependencies.
100103
This is not expected, since this means the dependency does not support the given targets which will
@@ -188,3 +191,13 @@ internal class SourceSetVisibilityProvider(
188191

189192
internal fun kotlinVariantNameFromPublishedVariantName(resolvedToVariantName: String): String =
190193
originalVariantNameFromPublished(resolvedToVariantName) ?: resolvedToVariantName
194+
195+
/**
196+
* Returns true when two components identifiers are from the same maven module (group + name)
197+
* Gradle projects can't be resolved into multiple versions since there is only one version of a project in gradle build
198+
*/
199+
private infix fun ComponentIdentifier.isEqualsIgnoringVersion(that: ComponentIdentifier): Boolean {
200+
if (this is ProjectComponentIdentifier && that is ProjectComponentIdentifier) return this == that
201+
if (this is ModuleComponentIdentifier && that is ModuleComponentIdentifier) return this.moduleIdentifier == that.moduleIdentifier
202+
return false
203+
}

0 commit comments

Comments
 (0)