From 510123b6f50bffddd85b247b3defcfbcfb4de4c7 Mon Sep 17 00:00:00 2001 From: nikky Date: Tue, 3 Jul 2018 14:02:32 +0200 Subject: [PATCH] buildscript cleanup for 1.10 and 1.11 --- 1.10.2/build.gradle | 50 +++++++++++-------- .../kotlin/matterlink/Constants.kt | 0 1.11.2/build.gradle | 45 ++++++++++------- .../kotlin/matterlink/Constants.kt | 0 .../kotlin/matterlink/config/BaseConfig.kt | 1 + 5 files changed, 55 insertions(+), 41 deletions(-) rename 1.10.2/src/{templates => main}/kotlin/matterlink/Constants.kt (100%) rename 1.11.2/src/{templates => main}/kotlin/matterlink/Constants.kt (100%) diff --git a/1.10.2/build.gradle b/1.10.2/build.gradle index 744b914..71400f8 100644 --- a/1.10.2/build.gradle +++ b/1.10.2/build.gradle @@ -1,4 +1,3 @@ - buildscript { repositories { jcenter() @@ -27,7 +26,7 @@ sourceCompatibility = targetCompatibility = '1.8' dependencies { compile project(':core') - compile group: "net.shadowfacts", name: "Forgelin", version: project.forgelin_version + compile group: "net.shadowfacts", name: "Forgelin", version: project.forgelin_version } shadowJar { @@ -45,31 +44,38 @@ shadowJar { } +import net.minecraftforge.gradle.user.TaskSourceCopy + +// Mad hacks to make source replacements work for Kotlin +// source: https://github.com/PaleoCrafter/VanillaImmersion/blob/ee82ecafb76659cf7d7822a722c8f63f43f41d01/build.gradle#L119 +for (set in sourceSets) { + def taskName = "source${set.name.capitalize()}Kotlin" + def dir = new File(project.getBuildDir(), "sources/${set.name}/kotlin") + task(taskName, type: TaskSourceCopy) { + source = set.getKotlin() + output = dir + } + def compileTask = tasks[set.getCompileTaskName("kotlin")] + compileTask.source = dir + compileTask.dependsOn taskName + def dirPath = dir.toPath() + compileKotlin.include { + return it.file.toPath().startsWith(dirPath) + } +} +sourceJar.from sourceSets.main.kotlin + minecraft { version = project.mc_version + "-" + project.forge_version runDir = "run" mappings = project.mcp_mappings -} -compileKotlin.doFirst { - def target = "src/main/kotlin/matterlink/gen" - copy { - from("src/templates/kotlin/matterlink/Constants.kt") - into(target) - } - ant.replaceregexp(match:'@MODVERSION@', replace: project.mod_version, flags:'g', byline:true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match:'@MCVERSION@', replace: project.mc_version, flags:'g', byline:true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match:'@FORGELIN-VERSION@', replace: project.forgelin_version, flags:'g', byline:true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match:'@FORGE-VERSION@', replace: project.forge_version, flags:'g', byline:true) { - fileset(dir: target, includes: 'Constants.kt') - } + replaceIn 'Constants.kt' + replace '@MODVERSION@', project.mod_version + replace '@MCVERSION@', project.mc_version + replace '@FORGELIN-VERSION@', project.forgelin_version + replace '@FORGE-VERSION@', project.forge_version } processResources { @@ -98,7 +104,7 @@ sourceJar { from sourceSets.main.allSource // copy everything else except the mcmod.info - from (project(":core").sourceSets.main.allSource) { + from(project(":core").sourceSets.main.allSource) { exclude 'mcmod.info' } } diff --git a/1.10.2/src/templates/kotlin/matterlink/Constants.kt b/1.10.2/src/main/kotlin/matterlink/Constants.kt similarity index 100% rename from 1.10.2/src/templates/kotlin/matterlink/Constants.kt rename to 1.10.2/src/main/kotlin/matterlink/Constants.kt diff --git a/1.11.2/build.gradle b/1.11.2/build.gradle index afa2478..fcae3a0 100644 --- a/1.11.2/build.gradle +++ b/1.11.2/build.gradle @@ -1,3 +1,5 @@ +import net.minecraftforge.gradle.user.TaskSourceCopy + buildscript { repositories { jcenter() @@ -46,31 +48,36 @@ shadowJar { exclude 'dummyThing' } +// Mad hacks to make source replacements work for Kotlin +// source: https://github.com/PaleoCrafter/VanillaImmersion/blob/ee82ecafb76659cf7d7822a722c8f63f43f41d01/build.gradle#L119 +for (set in sourceSets) { + def taskName = "source${set.name.capitalize()}Kotlin" + def dir = new File(project.getBuildDir(), "sources/${set.name}/kotlin") + task(taskName, type: TaskSourceCopy) { + source = set.getKotlin() + output = dir + } + def compileTask = tasks[set.getCompileTaskName("kotlin")] + compileTask.source = dir + compileTask.dependsOn taskName + def dirPath = dir.toPath() + compileKotlin.include { + return it.file.toPath().startsWith(dirPath) + } +} +sourceJar.from sourceSets.main.kotlin + minecraft { version = project.mc_version + "-" + project.forge_version runDir = "run" mappings = project.mcp_mappings -} -compileKotlin.doFirst { - def target = "src/main/kotlin/matterlink/gen" - copy { - from("src/templates/kotlin/matterlink/Constants.kt") - into(target) - } - ant.replaceregexp(match: '@MODVERSION@', replace: project.mod_version, flags: 'g', byline: true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match: '@MCVERSION@', replace: project.mc_version, flags: 'g', byline: true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match: '@FORGELIN-VERSION@', replace: project.forgelin_version, flags: 'g', byline: true) { - fileset(dir: target, includes: 'Constants.kt') - } - ant.replaceregexp(match: '@FORGE-VERSION@', replace: project.forge_version, flags: 'g', byline: true) { - fileset(dir: target, includes: 'Constants.kt') - } + replaceIn 'Constants.kt' + replace '@MODVERSION@', project.mod_version + replace '@MCVERSION@', project.mc_version + replace '@FORGELIN-VERSION@', project.forgelin_version + replace '@FORGE-VERSION@', project.forge_version } processResources { diff --git a/1.11.2/src/templates/kotlin/matterlink/Constants.kt b/1.11.2/src/main/kotlin/matterlink/Constants.kt similarity index 100% rename from 1.11.2/src/templates/kotlin/matterlink/Constants.kt rename to 1.11.2/src/main/kotlin/matterlink/Constants.kt diff --git a/core/src/main/kotlin/matterlink/config/BaseConfig.kt b/core/src/main/kotlin/matterlink/config/BaseConfig.kt index 77a1e07..5b6f820 100644 --- a/core/src/main/kotlin/matterlink/config/BaseConfig.kt +++ b/core/src/main/kotlin/matterlink/config/BaseConfig.kt @@ -358,6 +358,7 @@ data class BaseConfig(val rootDir: File) { jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject } catch (e: FileNotFoundException) { instance.error("creating config file $configFile") + configFile.absoluteFile.parentFile.mkdirs() configFile.createNewFile() jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject }