diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index d4d67889..dee21377 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -57,6 +57,11 @@ fun repos(vararg repos : String) { repos.forEach { Kobalt.addRepo(HostConfig(it)) } } +@Directive +fun buildFileClasspath(vararg deps: String) { + deps.forEach { Kobalt.addBuildFileClasspath(it) } +} + @Directive fun authRepos(vararg repos : HostConfig) { repos.forEach { Kobalt.addRepo(it) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index 29b9a6b2..075b23b5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -4,6 +4,7 @@ import com.beust.kobalt.Constants import com.beust.kobalt.HostConfig import com.beust.kobalt.Plugins import com.beust.kobalt.internal.PluginInfo +import com.beust.kobalt.maven.DependencyManager import com.google.inject.Guice import com.google.inject.Injector import com.google.inject.Module @@ -65,6 +66,13 @@ class Kobalt { if (repo.url.endsWith("/")) repo else repo.copy(url = (repo.url + "/"))) + val buildFileClasspath = arrayListOf() + + fun addBuildFileClasspath(dep: String) { + val dependencyManager = Kobalt.INJECTOR.getInstance(DependencyManager::class.java) + buildFileClasspath.add(dependencyManager.create(dep)) + } + private val KOBALT_PROPERTIES = "kobalt.properties" private val PROPERTY_KOBALT_VERSION = "kobalt.version" private val PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT = "kobalt.version.checkTimeout" // ISO-8601 diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 9beef9c8..7ace1fae 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -121,9 +121,11 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b log(2, " Need to recompile ${buildFile.name}") buildScriptJarFile.delete() + val buildFileClasspath = Kobalt.buildFileClasspath.map { it.jarFile.get() }.map { it.absolutePath } val result = kotlinCompilePrivate { classpath(files.kobaltJar) classpath(pluginUrls.map { it.file }) + classpath(buildFileClasspath) sourceFiles(listOf(buildFile.realPath.toFile().absolutePath)) output = buildScriptJarFile }.compile(context = context) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index 7d4933c1..219e3eda 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -22,6 +22,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val val dependencyManager: DependencyManager, val files: KFiles) { val pluginList = arrayListOf() val repos = arrayListOf() + val buildFileClasspath = arrayListOf() val profileLines = arrayListOf() val pluginUrls = arrayListOf() val projects = arrayListOf() @@ -51,6 +52,11 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val index = line.indexOf("repos(") if (index >= 0) { current = repos + } else { + index = line.indexOf("buildFileClasspath(") + if (index >= 0) { + current = buildFileClasspath + } } } } @@ -91,6 +97,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val repos.forEach { preBuildScript.add(it) } pluginList.forEach { preBuildScript.add(it) } + buildFileClasspath.forEach { preBuildScript.add(it) } } private fun initPluginUrls() {