From 7485e28e8c730d6b399ff6331e8bf883bbb3760c Mon Sep 17 00:00:00 2001 From: Thomas Tresansky Date: Mon, 17 Apr 2023 16:25:33 -0400 Subject: [PATCH] Fix inherited collection to not be always empty This fixes a mistake in PR #721 which used allDependencies here instead of dependencies, causing the inherited set always be empty, as a result of subtracting allDependencies from it. This also prevents inherited kotlin deps from being included in the latest set, to avoid issues with having the original and modifies dependencies both added to the copy. --- .../benmanes/gradle/versions/updates/Resolver.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/Resolver.kt b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/Resolver.kt index e307f0de..301c8d52 100644 --- a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/Resolver.kt +++ b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/Resolver.kt @@ -89,8 +89,11 @@ class Resolver( revision: String, currentCoordinates: Map, ): Configuration { + // Kotlin deps anywhere in the hierarchy are a special case we'll handle later + val kotlinDeps = { dependency: ExternalDependency -> dependency.group == "org.jetbrains.kotlin" && dependency.version != null } val latest = configuration.allDependencies .filterIsInstance() + .filterNot(kotlinDeps) .mapTo(mutableListOf()) { dependency -> createQueryDependency(dependency as ModuleDependency) } @@ -121,10 +124,10 @@ class Resolver( // Resolve using the latest version of explicitly declared dependencies and retains Kotlin's // inherited stdlib dependencies from the super configurations. This is required for variant // resolution, but the full set can break consumer capability matching. - val inherited = configuration.allDependencies + val inheritedKotlin = configuration.allDependencies .filterIsInstance() - .filter { dependency -> dependency.group == "org.jetbrains.kotlin" && dependency.version != null } - .minus(configuration.allDependencies) + .filter(kotlinDeps) + .minus(configuration.dependencies) // Adds the Kotlin 1.2.x legacy metadata to assist in variant selection val metadata = project.configurations.findByName("commonMainMetadataElements") @@ -139,7 +142,7 @@ class Resolver( copy.dependencies.clear() copy.dependencies.addAll(latest) - copy.dependencies.addAll(inherited) + copy.dependencies.addAll(inheritedKotlin) addRevisionFilter(copy, revision) addAttributes(copy, configuration)