From caf4b1c62a695c2216226c505d24f4bd77652e1d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 13:38:41 -0800 Subject: [PATCH] Fix StackOverFlow. Fixes https://github.com/cbeust/kobalt/issues/339. --- .../beust/kobalt/maven/aether/KobaltMavenResolver.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 69192c20..0320d456 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -45,7 +45,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null) = resolve(artifactToId(artifact), scope, filter) - fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : List { + fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null, + seen: HashSet = hashSetOf()) : List { val rr = resolve(id, scope, filter) val children = rr.root.children.filter { @@ -55,7 +56,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, } val result = listOf(artifactToId(rr.root.artifact)) + children.flatMap { val thisId = artifactToId(it.artifact) - resolveToIds(thisId, scope, filter) + if (! seen.contains(thisId)) { + seen.add(thisId) + resolveToIds(thisId, scope, filter, seen) + } else { + emptyList() + } } return result }