buildscript cleanup for 1.10 and 1.11

This commit is contained in:
nikky 2018-07-03 14:02:32 +02:00
parent 66229f4308
commit 510123b6f5
5 changed files with 55 additions and 41 deletions

View File

@ -1,4 +1,3 @@
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@ -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 { minecraft {
version = project.mc_version + "-" + project.forge_version version = project.mc_version + "-" + project.forge_version
runDir = "run" runDir = "run"
mappings = project.mcp_mappings mappings = project.mcp_mappings
}
compileKotlin.doFirst { replaceIn 'Constants.kt'
def target = "src/main/kotlin/matterlink/gen" replace '@MODVERSION@', project.mod_version
copy { replace '@MCVERSION@', project.mc_version
from("src/templates/kotlin/matterlink/Constants.kt") replace '@FORGELIN-VERSION@', project.forgelin_version
into(target) replace '@FORGE-VERSION@', project.forge_version
}
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')
}
} }
processResources { processResources {

View File

@ -1,3 +1,5 @@
import net.minecraftforge.gradle.user.TaskSourceCopy
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@ -46,31 +48,36 @@ shadowJar {
exclude 'dummyThing' 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 { minecraft {
version = project.mc_version + "-" + project.forge_version version = project.mc_version + "-" + project.forge_version
runDir = "run" runDir = "run"
mappings = project.mcp_mappings mappings = project.mcp_mappings
}
compileKotlin.doFirst { replaceIn 'Constants.kt'
def target = "src/main/kotlin/matterlink/gen" replace '@MODVERSION@', project.mod_version
copy { replace '@MCVERSION@', project.mc_version
from("src/templates/kotlin/matterlink/Constants.kt") replace '@FORGELIN-VERSION@', project.forgelin_version
into(target) replace '@FORGE-VERSION@', project.forge_version
}
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')
}
} }
processResources { processResources {

View File

@ -358,6 +358,7 @@ data class BaseConfig(val rootDir: File) {
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
instance.error("creating config file $configFile") instance.error("creating config file $configFile")
configFile.absoluteFile.parentFile.mkdirs()
configFile.createNewFile() configFile.createNewFile()
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
} }