From e9faa5c01f46b9bc19bfa8af8151eb764c8a4c50 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 28 Jul 2016 23:53:04 -0800 Subject: [PATCH] Forgot to reorder the dependencies. --- .../beust/kobalt/maven/DependencyManager2.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager2.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager2.kt index 22111b84..0972dac4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager2.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager2.kt @@ -7,8 +7,10 @@ import com.beust.kobalt.maven.aether.KobaltAether import com.beust.kobalt.maven.aether.Scope import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KFiles +import com.google.common.collect.ArrayListMultimap import com.google.inject.Inject import java.io.File +import java.util.* class DependencyManager2 @Inject constructor(val aether: KobaltAether) { /** @@ -110,7 +112,27 @@ class DependencyManager2 @Inject constructor(val aether: KobaltAether) { result.addAll(nonMavenDependencies) - return result.toList() + return reorderDependencies(result) + } + + /** + * Reorder dependencies so that if an artifact appears several times, only the one with the higest version + * is included. + */ + private fun reorderDependencies(dependencies: Collection): List { + val result = arrayListOf() + val map : ArrayListMultimap = ArrayListMultimap.create() + // The multilist maps each artifact to a list of all the versions found + // (e.g. {org.testng:testng -> (6.9.5, 6.9.4, 6.1.1)}), then we return just the first one + dependencies.forEach { + map.put(it.shortId, it) + } + for (k in map.keySet()) { + val l = map.get(k) + Collections.sort(l, Collections.reverseOrder()) + result.add(l[0]) + } + return result } private fun runClasspathContributors(project: Project?, context: KobaltContext) :