From 38288be20cb8729c3d11e0737f5ab9bc7d1de54d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 10 May 2016 03:15:26 -0800 Subject: [PATCH] [GITHUB-193] Fix multiple class path contributor call. Fixes https://github.com/cbeust/kobalt/issues/193 --- .../com/beust/kobalt/maven/DependencyManager.kt | 14 +++++++------- .../kotlin/com/beust/kobalt/maven/aether/Aether.kt | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 6085ad61..82d19d2d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -88,7 +88,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val override fun calculateDependencies(project: Project?, context: KobaltContext, dependentProjects: List, vararg allDependencies: List): List { - var result = arrayListOf() + val result = arrayListOf() allDependencies.forEach { dependencies -> result.addAll(transitiveClosure(dependencies)) } @@ -189,7 +189,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val private fun dependencies(project: Project, context: KobaltContext, isTest: Boolean) : List { - val result = arrayListOf() + val transitive = hashSetOf() val projects = listOf(ProjectDescription(project, project.projectExtra.dependsOn)) with(project) { val deps = arrayListOf(compileDependencies, compileProvidedDependencies) @@ -197,17 +197,17 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val deps.add(testDependencies) deps.add(testProvidedDependencies) } - deps.forEach { - result.addAll(calculateDependencies(project, context, projects, it)) + deps.filter { it.any() }.forEach { + transitive.addAll(calculateDependencies(project, context, projects, it)) } } // Make sure that classes/ and test-classes/ are always at the top of this classpath, // so that older versions of that project on the classpath don't shadow them - val result2 = listOf(FileDependency(KFiles.makeOutputDir(project).absolutePath), + val result = listOf(FileDependency(KFiles.makeOutputDir(project).absolutePath), FileDependency(KFiles.makeOutputTestDir(project).absolutePath)) + - reorderDependencies(result) - return result2 + reorderDependencies(transitive) + return result } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt index 5120c7ad..e2434513 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt @@ -220,6 +220,10 @@ class AetherDependency(val artifact: Artifact): IClasspathDependency, Comparable other.artifact.version)) } + override fun hashCode() = id.hashCode() + + override fun equals(other: Any?) = if (other is AetherDependency) other.id == id else false + override fun toString() = id }