Skip to content

Commit

Permalink
Fix inherited collection to not be always empty
Browse files Browse the repository at this point in the history
This fixes a mistake in PR ben-manes#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.
  • Loading branch information
tresat committed Apr 17, 2023
1 parent a43af6b commit 7485e28
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class Resolver(
revision: String,
currentCoordinates: Map<Coordinate.Key, Coordinate>,
): 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<ExternalDependency>()
.filterNot(kotlinDeps)
.mapTo(mutableListOf()) { dependency ->
createQueryDependency(dependency as ModuleDependency)
}
Expand Down Expand Up @@ -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<ExternalDependency>()
.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")
Expand All @@ -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)
Expand Down

0 comments on commit 7485e28

Please sign in to comment.