mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Automatically add artifacts of dependent projects.
This commit is contained in:
parent
12ad40edd0
commit
e88f3ac484
5 changed files with 75 additions and 39 deletions
|
@ -65,7 +65,6 @@ val kobalt = kotlinProject(wrapper) {
|
||||||
"org.jetbrains.dokka:dokka-fatjar:0.9.2",
|
"org.jetbrains.dokka:dokka-fatjar:0.9.2",
|
||||||
"org.jetbrains.kotlinx:kotlinx.dom:0.0.2",
|
"org.jetbrains.kotlinx:kotlinx.dom:0.0.2",
|
||||||
|
|
||||||
// file(homeDir("java/jcommander/target/jcommander-1.47.jar")),
|
|
||||||
"com.beust:jcommander:1.48",
|
"com.beust:jcommander:1.48",
|
||||||
"com.squareup.okhttp:okhttp:2.5.0",
|
"com.squareup.okhttp:okhttp:2.5.0",
|
||||||
"org.jsoup:jsoup:1.8.3",
|
"org.jsoup:jsoup:1.8.3",
|
||||||
|
@ -78,10 +77,7 @@ val kobalt = kotlinProject(wrapper) {
|
||||||
"io.reactivex:rxjava:1.0.16",
|
"io.reactivex:rxjava:1.0.16",
|
||||||
"com.google.code.gson:gson:2.4",
|
"com.google.code.gson:gson:2.4",
|
||||||
"com.squareup.retrofit:retrofit:1.9.0",
|
"com.squareup.retrofit:retrofit:1.9.0",
|
||||||
"com.squareup.okio:okio:1.6.0",
|
"com.squareup.okio:okio:1.6.0"
|
||||||
// "com.squareup.retrofit:retrofit:2.0.0-beta2",
|
|
||||||
// "com.squareup.retrofit:converter-gson:2.0.0-beta2",
|
|
||||||
file("modules/wrapper/kobaltBuild/libs/kobalt-wrapper.jar")
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.api.BasePlugin
|
import com.beust.kobalt.api.BasePlugin
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.api.ProjectDescription
|
||||||
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
import com.beust.kobalt.maven.*
|
import com.beust.kobalt.maven.*
|
||||||
|
@ -129,4 +130,34 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
||||||
fun addCompilerArgs(vararg args: String) {
|
fun addCompilerArgs(vararg args: String) {
|
||||||
compilerArgs.addAll(args)
|
compilerArgs.addAll(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findSourceFiles(dir: String, sourceDirectories: Collection<String>): List<String> {
|
||||||
|
val projectDir = File(dir)
|
||||||
|
return files.findRecursively(projectDir,
|
||||||
|
sourceDirectories.map { File(it) }) { it: String -> it.endsWith(".java") }
|
||||||
|
.map { File(projectDir, it).absolutePath }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun baseTaskCompile(project: Project, projectDescriptions: List<ProjectDescription>) : TaskResult {
|
||||||
|
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||||
|
|
||||||
|
val projDeps = dependencyManager.dependentProjectDependencies(projectDescriptions, project, context)
|
||||||
|
|
||||||
|
val classpath = dependencyManager.calculateDependencies(project, context, project.compileDependencies,
|
||||||
|
project.compileProvidedDependencies, projDeps)
|
||||||
|
|
||||||
|
val projectDirectory = File(project.directory)
|
||||||
|
val buildDirectory = File(projectDirectory, project.buildDirectory + File.separator + "classes")
|
||||||
|
buildDirectory.mkdirs()
|
||||||
|
|
||||||
|
val sourceFiles = files.findRecursively(projectDirectory, project.sourceDirectories.map { File(it) },
|
||||||
|
{ it .endsWith(project.sourceSuffix) })
|
||||||
|
.map { File(projectDirectory, it).absolutePath }
|
||||||
|
|
||||||
|
val result = doCompile(project, classpath, sourceFiles, buildDirectory)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>,
|
||||||
|
buildDirectory: File) : TaskResult
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package com.beust.kobalt.maven
|
||||||
import com.beust.kobalt.api.IClasspathContributor
|
import com.beust.kobalt.api.IClasspathContributor
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.api.ProjectDescription
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
||||||
import com.google.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -81,4 +83,24 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this project depends on other projects, we need to include their jar file and also
|
||||||
|
* their own dependencies
|
||||||
|
*/
|
||||||
|
fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>,
|
||||||
|
project: Project, context: KobaltContext) :
|
||||||
|
List<IClasspathDependency> {
|
||||||
|
val result = arrayListOf<IClasspathDependency>()
|
||||||
|
projectDescriptions.filter {
|
||||||
|
it.project.name == project.name
|
||||||
|
}.forEach { pd ->
|
||||||
|
pd.dependsOn.forEach { p ->
|
||||||
|
result.add(FileDependency(p.projectProperties.getString(PackagingPlugin.JAR_NAME)))
|
||||||
|
result.addAll(calculateDependencies(p, context))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.beust.kobalt.internal.JvmCompiler
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
|
import com.beust.kobalt.maven.IClasspathDependency
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
@ -73,15 +74,15 @@ public class JavaPlugin @Inject constructor(
|
||||||
|
|
||||||
@Task(name = TASK_COMPILE, description = "Compile the project")
|
@Task(name = TASK_COMPILE, description = "Compile the project")
|
||||||
fun taskCompile(project: Project) : TaskResult {
|
fun taskCompile(project: Project) : TaskResult {
|
||||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
return baseTaskCompile(project, projects())
|
||||||
val projectDir = File(project.directory)
|
}
|
||||||
val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
|
|
||||||
|
override fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>,
|
||||||
|
buildDirectory: File) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (sourceFiles.size > 0) {
|
if (sourceFiles.size > 0) {
|
||||||
val buildDir = File(projectDir, project.buildDirectory + File.separator + "classes")
|
javaCompiler.compile(project, context, classpath, sourceFiles,
|
||||||
.apply { mkdirs() }
|
buildDirectory, compilerArgs)
|
||||||
javaCompiler.compile(project, context, project.compileDependencies, sourceFiles,
|
|
||||||
buildDir, compilerArgs)
|
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any source files to compile")
|
warn("Couldn't find any source files to compile")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
@ -105,13 +106,6 @@ public class JavaPlugin @Inject constructor(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findSourceFiles(dir: String, sourceDirectories: Collection<String>): List<String> {
|
|
||||||
val projectDir = File(dir)
|
|
||||||
return files.findRecursively(projectDir,
|
|
||||||
sourceDirectories.map { File(it) }) { it: String -> it.endsWith(".java") }
|
|
||||||
.map { File(projectDir, it).absolutePath }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun projects() = projects
|
override fun projects() = projects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,27 +36,20 @@ class KotlinPlugin @Inject constructor(
|
||||||
|
|
||||||
@Task(name = TASK_COMPILE, description = "Compile the project")
|
@Task(name = TASK_COMPILE, description = "Compile the project")
|
||||||
fun taskCompile(project: Project): TaskResult {
|
fun taskCompile(project: Project): TaskResult {
|
||||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
return baseTaskCompile(project, projects())
|
||||||
val classpath = dependencyManager.calculateDependencies(project, context, project.compileDependencies,
|
}
|
||||||
project.compileProvidedDependencies)
|
|
||||||
|
|
||||||
val projectDirectory = java.io.File(project.directory)
|
|
||||||
val buildDirectory = File(projectDirectory, project.buildDirectory + File.separator + "classes")
|
|
||||||
buildDirectory.mkdirs()
|
|
||||||
|
|
||||||
val sourceFiles = files.findRecursively(projectDirectory, project.sourceDirectories.map { File(it) },
|
|
||||||
{ it .endsWith(".kt") })
|
|
||||||
.map { File(projectDirectory, it).absolutePath }
|
|
||||||
|
|
||||||
|
override fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>,
|
||||||
|
buildDirectory: File) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (sourceFiles.size > 0) {
|
if (sourceFiles.size > 0) {
|
||||||
compilePrivate(project, classpath, sourceFiles, buildDirectory)
|
compilePrivate(project, classpath, sourceFiles, buildDirectory)
|
||||||
lp(project, "Compilation succeeded")
|
lp(project, "Compilation succeeded")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any source files")
|
warn("Couldn't find any source files")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +59,7 @@ class KotlinPlugin @Inject constructor(
|
||||||
val projectDir = File(project.directory)
|
val projectDir = File(project.directory)
|
||||||
|
|
||||||
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectoriesTest.map { File(it) })
|
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectoriesTest.map { File(it) })
|
||||||
{ it: String -> it.endsWith(".kt") }
|
{ it: String -> it.endsWith(project.sourceSuffix) }
|
||||||
.map { File(projectDir, it).absolutePath }
|
.map { File(projectDir, it).absolutePath }
|
||||||
|
|
||||||
val result =
|
val result =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue