MinecraftForge build.gradle.kts version 1.16
Minecraft 1.16 で build.gradle を build.gradle.kts (Kotlin Script だとか Kotlin DSL とか言われているやつ) に書き直してみようとした。細かく言うと version 1.16.2 でこの作業をした。
ソースをまず貼っちゃう
元
code:build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
version = '0.0.1'
group = 'sarubo.s_add_things'
archivesBaseName = 's_add_things'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
println('Java: ' + System.getProperty('java.version')
+ ' JVM: ' + System.getProperty('java.vm.version')
+ '(' + System.getProperty('java.vendor')
+ ') Arch: ' + System.getProperty('os.arch')
)
minecraft {
mappings channel: 'snapshot', version: '20200514-1.16'
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
s_add_things {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
s_add_things {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
args '--mod', 's_add_things', '--all', '--output', file('src/generated/resources/')
mods {
s_add_things {
source sourceSets.main
}
}
}
}
}
dependencies {
minecraft 'net.minecraftforge:forge:1.16.2-33.0.20'
}
jar {
manifest {
attributes([
"Specification-Title" : "s_add_things",
"Specification-Vendor" : "sarubo",
"Specification-Version" : "0", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Vendor" : "sarubo",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
jar.finalizedBy('reobfJar')
// publish.dependsOn('reobfJar')
// publishing {
// publications {
// mavenJava(MavenPublication) {
// artifact jar
// }
// }
// repositories {
// maven {
// url "file:///${project.projectDir}/mcmodsrepo"
// }
// }
// }
tasks.withType(Jar) {
compileJava.options.encoding = 'UTF-8'
}
新しい
code:settings.gradle.kts
buildscript {
this.repositories {
this.jcenter()
this.mavenCentral()
}
this.dependencies {
this.classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "4.+") {
this.isChanging = true
}
}
}
code:build.gradle.kts
import net.minecraftforge.gradle.common.util.RunConfig
import org.gradle.api.tasks.bundling.Jar
import java.time.Instant
plugins {
this.id("net.minecraftforge.gradle")
}
val myModVersion = "0.0.1"
val archivesBaseName = "s_add_things"
val minecraftVersion = "1.16.2"
val mappingsMinecraftVersion = "1.16"
val forgeVersion = "33.0.20"
val compileJava by tasks.existing(JavaCompile::class)
val jvmMinorVersionString = "1.8"
compileJava.configure {
this.sourceCompatibility = jvmMinorVersionString
this.targetCompatibility = jvmMinorVersionString
this.options.encoding = "UTF-8"
}
println("Java: " + System.getProperty("java.version")
+ " JVM: " + System.getProperty("java.vm.version")
+ "(" + System.getProperty("java.vendor")
+ ") Arch: " + System.getProperty("os.arch")
)
minecraft {
this.mappings(mapOf(
"channel" to "snapshot",
"version" to "20200514-$mappingsMinecraftVersion"
))
this.runs {
val runConfig = Action<RunConfig> {
this.properties(mapOf(
"forge.logging.markers" to "SCAN,REGISTRIES,REGISTRYDUMP",
"forge.logging.console.level" to "debug"
))
this.workingDirectory = project.file("run").canonicalPath
this.mods {
this.create(project.name) {
}
}
}
this.create("client", runConfig)
this.create("server", runConfig)
this.create("data") {
runConfig.execute(this)
args("--mod", "s_add_things", "--all", "--output",
file("src/generated/resources/")
)
}
}
}
dependencies {
minecraft("net.minecraftforge:forge:$minecraftVersion-$forgeVersion")
}
tasks.withType<Jar> {
this.manifest {
this.attributes(mapOf(
"Specification-Title" to "s_add_things",
"Specification-Vendor" to "sarubo",
"Specification-Version" to "0", // We are version 1 of ourselves
"Implementation-Title" to project.name,
"Implementation-Version" to myModVersion,
"Implementation-Vendor" to "sarubo",
"Implementation-Timestamp" to Instant.now().toString()
))
}
this.finalizedBy("reobfJar")
// publish.dependsOn('reobfJar')
// publishing {
// publications {
// mavenJava(MavenPublication) {
// artifact jar
// }
// }
// repositories {
// maven {
// url "file:///${project.projectDir}/mcmodsrepo"
// }
// }
// }
}
シンタックスハイライトされない…… どうして…… どうして……
調べればすぐ出たり、補完でわかるくらいの変更は特筆するところではないかな。わからん。
特筆事項
s_add_things や sarubo やらは私のprojectだから書いているので適宜変えるべし
gradle-wapper.properties ファイルで distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip に変える(重要)
buildscript はsettings.gradle.kts に書く(重要)
buildscript 内の this.dependencies 内の this.crasspath の名前付き引数の version は "3.+" から "4.+" に変える(重要)
buildscript 内の this.dependencies 内の this.crasspath の changing は波括弧の中で this.isChanging = true で解決
compileJava ってなんだよ。 tasks から引っ張ってこい。
minecraft のコードブロックは configure<UserDevExtension> (import net.minecraftforge.gradle.userdev.UserDevExtension) するのもあり。知らんけど。
new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") なんて出来ないので Instant.now().toString() で済ませる。