From 736062ab8b51dcbdbae18e017c7c5f764b7bd1ef Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 23 Sep 2016 11:32:50 -0700 Subject: [PATCH] Prevent duplicate dependency tags in the .pom. --- .../kotlin/com/beust/kobalt/maven/PomGenerator.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt index fddfe657..6d666726 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt @@ -1,6 +1,7 @@ package com.beust.kobalt.maven import com.beust.kobalt.SystemProperties +import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Project import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog @@ -62,8 +63,17 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) { // pom.dependencies = arrayListOf() + /** + * optional and provided dependencies are added both to the compile dependencies (since they are needed + * to build the project) and to their respective list as well (for POM generation). Make sure they + * don't get added twice to the .pom in such cases. + */ + fun providedOrOptional(dep: IClasspathDependency) = + project.compileProvidedDependencies.contains(dep) || + project.optionalDependencies.contains(dep) + // Compile dependencies - project.compileDependencies.forEach { dep -> + project.compileDependencies.filterNot(::providedOrOptional).forEach { dep -> pom.dependencies.add(dep.toMavenDependencies()) }