diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index 7ec632d9..a340662b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -75,9 +75,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager File(project.directory, buildDirectory.path).mkdirs() // Remove all the excluded dependencies from the classpath - var classpath = fullClasspath.filter { - ! isDependencyExcluded(it, project.excludedDependencies) - } + var classpath = fullClasspath // The classpath needs to contain $buildDirectory/classes as well so that projects that contain // multiple languages can use classes compiled by the compiler run before them. @@ -225,15 +223,4 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager } return result } - - companion object { - /** - * Naïve implementation: just exclude all dependencies that start with one of the excluded dependencies. - * Should probably make exclusion more generic (full on string) or allow exclusion to be specified - * formally by groupId or artifactId. - */ - fun isDependencyExcluded(dep: IClasspathDependency, excluded: List) - = excluded.any { excluded -> dep.id.startsWith(excluded.id) } - - } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 3690969a..fc7b83cd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -91,9 +91,7 @@ open class JvmCompilerPlugin @Inject constructor( scopes = listOf(Scope.TEST)) val compileDependencies = dependencyManager.calculateDependencies(project, context, scopes = listOf(Scope.COMPILE)) - val allDependencies = (compileDependencies + testDependencies) - .toHashSet() - .filter { ! CompilerUtils.isDependencyExcluded(it, project.excludedDependencies) } + val allDependencies = (compileDependencies + testDependencies).toHashSet() return testContributor.run(project, context, configName, allDependencies.toList()) } else { context.logger.log(project.name, 2, 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 03641845..d5b4cd2b 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 @@ -85,8 +85,10 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, // project.compileDependencies + project.compileRuntimeDependencies) /** - * @return the classpath for this project, including the IClasspathContributors. - * allDependencies is typically either compileDependencies or testDependencies. If no dependencies + * @return the classpath for this project, including the IClasspathContributors. Excluded dependencies + * are removed from the result. + * + * @param{allDependencies} is typically either compileDependencies or testDependencies. If no dependencies * are passed, they are calculated from the scope filters. */ override fun calculateDependencies(project: Project?, context: KobaltContext, @@ -130,10 +132,24 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, result.addAll(runClasspathContributors(project, context)) result.addAll(dependentProjectDependencies(project, context, dependencyFilter, scopes)) + /** + * Naïve implementation: just exclude all dependencies that start with one of the excluded dependencies. + * Should probably make exclusion more generic (full on string) or allow exclusion to be specified + * formally by groupId or artifactId. + */ + fun isDependencyExcluded(dep: IClasspathDependency, excluded: List) + = excluded.any { excluded -> dep.id.startsWith(excluded.id) } + // Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones, // we need to reorder them again in case we're adding dependencies that are already present // but with a different version - val reordered = reorderDependencies(result) + val shortResult = + if (project != null) { + result.filter { ! isDependencyExcluded(it, project.excludedDependencies) } + } else { + result + } + val reordered = reorderDependencies(shortResult) return reordered }