9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 17:39:30 +00:00

build(client-mod): 将 build.gradle 重命名为 build.gradle.kts并进行重构

This commit is contained in:
jhqwqmc
2025-03-24 07:17:52 +08:00
parent 098e1538d5
commit ddc605e368
2 changed files with 95 additions and 90 deletions

View File

@@ -1,90 +0,0 @@
plugins {
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'com.gradleup.shadow' version '9.0.0-beta11'
}
version = project.project_version
group = project.project_group
base {
archivesName = "craft-engine-fabric-mod"
}
sourceSets {
client {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
main {
output.dir(client.output)
}
}
shadowJar {
relocate('org.yaml', 'net.momirealms.craftengine.libraries.org.yaml')
configurations = [project.configurations.shadow]
archiveFileName = "${base.archivesName.get()}-${project.version}-shadow.jar"
from sourceSets.main.output
from sourceSets.client.output
}
remapJar {
dependsOn shadowJar
inputFile = shadowJar.archiveFile
destinationDirectory = file("$rootDir/target")
archiveFileName = "${base.archivesName.get()}-${project.version}.jar"
}
loom {
mods {
"craft-engine-fabric-mod" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}
configurations {
shadow
implementation.extendsFrom(shadow)
}
dependencies {
minecraft "com.mojang:minecraft:${project.latest_minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
shadow 'org.yaml:snakeyaml:2.4'
}
processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.latest_minecraft_version
inputs.property "loader_version", project.loader_version
filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.latest_minecraft_version,
"loader_version": project.loader_version
}
}
def targetJavaVersion = 21
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release.set(targetJavaVersion)
}
}
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
withSourcesJar()
}
tasks.build.dependsOn

View File

@@ -0,0 +1,95 @@
plugins {
id("fabric-loom") version "1.10-SNAPSHOT"
id("com.gradleup.shadow") version "9.0.0-beta11"
}
version = property("project_version")!!
group = property("project_group")!!
val project_version: String by project
val latest_minecraft_version: String by project
val loader_version: String by project
base {
archivesName.set("craft-engine-fabric-mod")
}
sourceSets {
create("client") {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
}
main {
output.dir(sourceSets["client"].output)
}
}
tasks.shadowJar {
relocate("org.yaml", "net.momirealms.craftengine.libraries.org.yaml")
configurations = listOf(project.configurations.getByName("shadow"))
archiveFileName.set("${base.archivesName.get()}-${project.version}-shadow.jar")
from(sourceSets.main.get().output)
from(sourceSets["client"].output)
}
tasks.remapJar {
dependsOn(tasks.shadowJar)
inputFile.set(tasks.shadowJar.get().archiveFile)
destinationDirectory.set(file("$rootDir/target"))
archiveFileName.set("${base.archivesName.get()}-${project.version}.jar")
}
loom {
mods {
create("craft-engine-fabric-mod") {
sourceSet(sourceSets.main.get())
sourceSet(sourceSets["client"])
}
}
}
dependencies {
minecraft("com.mojang:minecraft:${property("latest_minecraft_version")}")
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")
modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}")
add("shadow", "org.yaml:snakeyaml:2.4")
}
tasks.processResources {
inputs.property("version", project_version)
inputs.property("minecraft_version", latest_minecraft_version)
inputs.property("loader_version", loader_version)
filteringCharset = "UTF-8"
filesMatching("fabric.mod.json") {
expand(
"version" to project_version,
"minecraft_version" to latest_minecraft_version,
"loader_version" to loader_version
)
}
}
val targetJavaVersion = 21
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible) {
options.release.set(targetJavaVersion)
}
}
java {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain {
languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
}
}
withSourcesJar()
}
tasks.build {
dependsOn(tasks.shadowJar)
}