From e03b4527ad53d67785aa82e78df993f36b1e5e70 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Feb 2017 10:03:24 -0800 Subject: [PATCH] Handle dependency exclusion for tests too. --- .../beust/kobalt/internal/CompilerUtils.kt | 20 ++++++++++--------- .../kobalt/internal/JvmCompilerPlugin.kt | 4 +++- 2 files changed, 14 insertions(+), 10 deletions(-) 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 0cf9035b..87c3970d 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 @@ -204,15 +204,6 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager } } - - /** - * 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. - */ - private fun isDependencyExcluded(id: IClasspathDependency, excluded: List) - = excluded.any { id.id.startsWith(it.id) } - fun sourceCompilerFlags(project: Project?, context: KobaltContext, info: CompilerActionInfo) : List { val adapters = context.pluginInfo.compilerFlagContributors.map { val closure = { project: Project, context: KobaltContext, currentFlags: List, @@ -234,4 +225,15 @@ 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 c268f774..c8faa66f 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,7 +91,9 @@ open class JvmCompilerPlugin @Inject constructor( scopes = listOf(Scope.TEST)) val compileDependencies = dependencyManager.calculateDependencies(project, context, scopes = listOf(Scope.COMPILE)) - val allDependencies = (compileDependencies + testDependencies).toHashSet() + val allDependencies = (compileDependencies + testDependencies) + .toHashSet() + .filter { ! CompilerUtils.isDependencyExcluded(it, project.excludedDependencies) } return testContributor.run(project, context, configName, allDependencies.toList()) } else { context.logger.log(project.name, 2,