diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt index 16ad1f75..a4d2bc36 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt @@ -25,7 +25,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) // Dependencies val allDependencies = (info.dependencies - + dependencyManager.calculateDependencies(project, context!!, info.dependencies)) + + dependencyManager.calculateDependencies(project, context!!, allDependencies = info.dependencies)) .distinct() // Plugins that add flags to the compiler diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index ab1aab30..cba00309 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -31,6 +31,9 @@ abstract class JvmCompilerPlugin @Inject constructor( @ExportedProjectProperty(doc = "The location of the build directory", type = "String") const val BUILD_DIR = "buildDir" + @ExportedProjectProperty(doc = "Projects this project depends on", type = "List") + const val DEPENDENT_PROJECTS = "dependentProjects" + const val TASK_CLEAN = "clean" const val TASK_TEST = "test" @@ -49,6 +52,7 @@ abstract class JvmCompilerPlugin @Inject constructor( override fun apply(project: Project, context: KobaltContext) { super.apply(project, context) project.projectProperties.put(BUILD_DIR, project.buildDirectory + File.separator + "classes") + project.projectProperties.put(DEPENDENT_PROJECTS, projects()) } /** @@ -61,7 +65,7 @@ abstract class JvmCompilerPlugin @Inject constructor( with(project) { arrayListOf(compileDependencies, compileProvidedDependencies, testDependencies, testProvidedDependencies).forEach { - result.addAll(dependencyManager.calculateDependencies(project, context, it)) + result.addAll(dependencyManager.calculateDependencies(project, context, projects(), it)) } } val result2 = dependencyManager.reorderDependencies(result) @@ -152,10 +156,8 @@ abstract class JvmCompilerPlugin @Inject constructor( private fun createCompilerActionInfo(project: Project) : CompilerActionInfo { copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN) - val projDeps = dependencyManager.dependentProjectDependencies(projects(), project, context) - - val classpath = dependencyManager.calculateDependencies(project, context, project.compileDependencies, - project.compileProvidedDependencies, projDeps) + val classpath = dependencyManager.calculateDependencies(project, context, projects, + project.compileDependencies) val projectDirectory = File(project.directory) val buildDirectory = File(projectDirectory, project.buildDirectory + File.separator + "classes") diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt index b15eaba8..bf2522bc 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt @@ -7,7 +7,6 @@ import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.maven.DependencyManager -import com.beust.kobalt.maven.IClasspathDependency import com.beust.kobalt.misc.* import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import com.google.inject.assistedinject.Assisted @@ -194,7 +193,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b } private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File) { - val kotlintDeps = dependencyManager.calculateDependencies(null, context, listOf()) + val kotlintDeps = dependencyManager.calculateDependencies(null, context) val deps: List = kotlintDeps.map { it.jarFile.get().absolutePath } kotlinCompilePrivate { classpath(files.kobaltJar) diff --git a/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 9d1a4212..4d229ed5 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -21,12 +21,14 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor * @return the classpath for this project, including the IClasspathContributors. */ fun calculateDependencies(project: Project?, context: KobaltContext, + dependentProjects: List = emptyList(), vararg allDependencies: List): List { var result = arrayListOf() allDependencies.forEach { dependencies -> result.addAll(transitiveClosure(dependencies)) } result.addAll(runClasspathContributors(project, context)) + result.addAll(dependentProjectDependencies(dependentProjects, project, context)) return result } @@ -90,12 +92,12 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor * If this project depends on other projects, we need to include their jar file and also * their own dependencies */ - fun dependentProjectDependencies(projectDescriptions: List, - project: Project, context: KobaltContext) : + private fun dependentProjectDependencies(projectDescriptions: List, + project: Project?, context: KobaltContext) : List { val result = arrayListOf() projectDescriptions.filter { - it.project.name == project.name + it.project.name == project?.name }.forEach { pd -> pd.dependsOn.forEach { p -> val classesDir = p.projectProperties.getString(JvmCompilerPlugin.BUILD_DIR) @@ -104,7 +106,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor } else { warn("Couldn't find any classes dir for project depended on ${p.name}") } - result.addAll(calculateDependencies(p, context)) + result.addAll(calculateDependencies(p, context, projectDescriptions)) } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index 9832aea8..d86730b4 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -3,8 +3,10 @@ package com.beust.kobalt.plugin.application import com.beust.kobalt.* import com.beust.kobalt.api.ConfigPlugin import com.beust.kobalt.api.Project +import com.beust.kobalt.api.ProjectDescription import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.RunCommand @@ -42,6 +44,7 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors, @Task(name = "run", description = "Run the main class", runAfter = arrayOf("assemble")) fun taskRun(project: Project): TaskResult { + var result = TaskResult() configurationFor(project)?.let { config -> val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!! if (config.mainClass != null) { @@ -49,22 +52,31 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors, val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List val allDeps = arrayListOf(jarName) if (! isFatJar(packages, jarName)) { + val projDeps = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) + as List // If the jar file is not fat, we need to add the transitive closure of all dependencies // on the classpath allDeps.addAll( - dependencyManager.calculateDependencies(project, context, project.compileDependencies) - .map { it.jarFile.get().path }) + dependencyManager.calculateDependencies(project, context, projDeps, + allDependencies = project.compileDependencies).map { it.jarFile.get().path }) } val allDepsJoined = allDeps.joinToString(File.pathSeparator) val args = listOf("-classpath", allDepsJoined) + config.jvmArgs + config.mainClass!! - RunCommand(java.absolutePath).run(args, successCallback = { output: List -> - println(output.joinToString("\n")) - }) + val exitCode = RunCommand(java.absolutePath).run(args, + successCallback = { output: List -> + println(output.joinToString("\n")) + }, + errorCallback = { output: List -> + println("ERROR") + println(output.joinToString("\n")) + } + ) + result = TaskResult(exitCode == 0) } else { throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}") } } - return TaskResult() + return result } private fun isFatJar(packages: List, jarName: String): Boolean {