Treat each plugin as an individual source set

Adds separate build tasks for each plugin by auto-discovering plugin meta
files in the build script.  Each plugin will automatically have its
main sources and tests compiled, and then it's output added to the game
modules classpath.

This enables support for incremental compilation of scripts, as well as
unit testing using Gradle's test framework.
This commit is contained in:
Gary Tierney
2017-05-30 02:19:09 +01:00
parent 4ee123a59d
commit 3fb6d3f792
23 changed files with 225 additions and 80 deletions
+6 -42
View File
@@ -7,59 +7,23 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.1'
}
}
apply plugin: 'kotlin'
ext.pluginsDir = "$projectDir/src/plugins"
sourceSets {
plugins {
kotlin {
srcDir "$pluginsDir"
exclude 'stub.kt'
exclude '**/*.kts'
}
}
}
apply plugin: 'kotlin'
apply from: 'plugins.gradle'
dependencies {
compile project(':cache')
compile project(':net')
compile project(':util')
pluginsCompile(configurations.compile)
pluginsCompile(sourceSets.main.output)
compile group: 'io.github.lukehutch', name: 'fast-classpath-scanner', version: '2.0.21'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: "$kotlinVersion"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-compiler', version: "$kotlinVersion"
runtime files("$buildDir/plugins")
runtime sourceSets.plugins.output
}
task compilePluginScripts(type: JavaExec, dependsOn: [classes, pluginsClasses]) {
group = LifecycleBasePlugin.BUILD_GROUP
description = 'Compile plugin script files (.plugin.kts) to java bytecode'
def compilerClasspath = [
configurations.compile.asPath,
configurations.runtime.asPath,
sourceSets.main.compileClasspath.asPath,
sourceSets.main.runtimeClasspath.asPath
]
def outputDir = "$buildDir/plugins"
def manifestPath = "$buildDir/plugins/manifest.txt"
inputs.source "$pluginsDir"
outputs.dir outputDir
classpath = sourceSets.main.compileClasspath + sourceSets.main.runtimeClasspath
main = 'org.apollo.game.plugin.kotlin.KotlinPluginCompiler'
args = ["$pluginsDir", outputDir, manifestPath, compilerClasspath.join(':')]
}
assemble.dependsOn compilePluginScripts
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
}