diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt index 395e249a..2a7d7b29 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt @@ -2,7 +2,7 @@ package com.beust.kobalt.api import com.beust.kobalt.TaskResult -interface ICompiler { +interface ICompiler : Comparable { /** * The suffixes handled by this compiler (without the dot, e.g. "java" or "kt"). */ @@ -17,6 +17,17 @@ interface ICompiler { * Run the compilation based on the info. */ fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult + + companion object { + val DEFAULT_PRIORITY: Int = 5 + } + + /** + * The priority of this compiler. Lower priority compilers are run first. + */ + val priority: Int get() = DEFAULT_PRIORITY + + override fun compareTo(other: ICompiler) = priority.compareTo(other.priority) } interface ICompilerContributor : IProjectAffinity { 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 c6839b61..623cdf3f 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 @@ -194,29 +194,28 @@ open class JvmCompilerPlugin @Inject constructor( if (compilerContributors.isEmpty()) { throw KobaltException("Couldn't find any compiler for project ${project.name}") } else { - compilerContributors.forEach { contributor -> - contributor.compilersFor(project, context).forEach { compiler -> - val contributedSourceDirs = - if (isTest) { - context.testSourceDirectories(project) - } else { - context.sourceDirectories(project) - } - val sourceFiles = KFiles.findSourceFiles(project.directory, - contributedSourceDirs.map { it.path }, compiler.sourceSuffixes) - if (sourceFiles.size > 0) { - // TODO: createCompilerActionInfo recalculates the source files, only compute them - // once and pass them - val info = createCompilerActionInfo(project, context, isTest, sourceDirectories, - sourceSuffixes = compiler.sourceSuffixes) - val thisResult = compiler.compile(project, context, info) - results.add(thisResult) - if (!thisResult.success && failedResult == null) { - failedResult = thisResult - } + val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted() + allCompilers.forEach { compiler -> + val contributedSourceDirs = + if (isTest) { + context.testSourceDirectories(project) } else { - log(2, "Compiler $compiler not running on ${project.name} since no source files were found") + context.sourceDirectories(project) } + val sourceFiles = KFiles.findSourceFiles(project.directory, + contributedSourceDirs.map { it.path }, compiler.sourceSuffixes) + if (sourceFiles.size > 0) { + // TODO: createCompilerActionInfo recalculates the source files, only compute them + // once and pass them + val info = createCompilerActionInfo(project, context, isTest, sourceDirectories, + sourceSuffixes = compiler.sourceSuffixes) + val thisResult = compiler.compile(project, context, info) + results.add(thisResult) + if (!thisResult.success && failedResult == null) { + failedResult = thisResult + } + } else { + log(2, "Compiler $compiler not running on ${project.name} since no source files were found") } } return if (failedResult != null) failedResult!! diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index bbdd3fef..ab03ca1f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -19,8 +19,7 @@ import javax.inject.Singleton @Singleton class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager, override val configActor: ConfigActor) - : BaseJvmPlugin(configActor), IDocContributor, IClasspathContributor, ICompilerContributor, - IBuildConfigContributor { + : BaseJvmPlugin(configActor), IDocContributor, IClasspathContributor, ICompilerContributor, IBuildConfigContributor { companion object { const val PLUGIN_NAME = "Kotlin" @@ -116,6 +115,9 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen val compiler = object: ICompiler { override val sourceSuffixes = listOf("kt") + /** The Kotlin compiler should run before the Java one */ + override val priority: Int get() = ICompiler.DEFAULT_PRIORITY - 1 + override val sourceDirectory = "kotlin" override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {