[Gradle] Break cycles when iterating over all dependencies
Gradle DependencyResult can have cycles in its dependencies. So keep track of visited dependencies. ^KT-49933
This commit is contained in:
committed by
Space Team
parent
32cb38e0d4
commit
007a2411cc
+7
-2
@@ -10,6 +10,7 @@ import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ResolveException
|
||||
import org.gradle.api.artifacts.result.*
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.jetbrains.kotlin.tooling.core.withClosure
|
||||
|
||||
/**
|
||||
* Represents a Gradle Configuration that was resolved after configuration time.
|
||||
@@ -41,12 +42,16 @@ private constructor(
|
||||
private val artifactsByComponentId by TransientLazy { artifacts.groupBy { it.id.componentIdentifier } }
|
||||
|
||||
val allDependencies: List<DependencyResult> get() {
|
||||
fun DependencyResult.allDependenciesRecursive(): List<DependencyResult> =
|
||||
if (this is ResolvedDependencyResult) {
|
||||
val visited = mutableSetOf<DependencyResult>()
|
||||
fun DependencyResult.allDependenciesRecursive(): List<DependencyResult> {
|
||||
if (this in visited) return emptyList()
|
||||
visited += this
|
||||
return if (this is ResolvedDependencyResult) {
|
||||
listOf(this) + selected.dependencies.flatMap { it.allDependenciesRecursive() }
|
||||
} else {
|
||||
listOf(this)
|
||||
}
|
||||
}
|
||||
|
||||
return root.dependencies.flatMap { it.allDependenciesRecursive() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user