Skip to content

Commit

Permalink
Optimizing the fabric.mod.json Processing
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Aug 25, 2023
1 parent c1d0e8c commit fadc597
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 23 additions & 10 deletions fabricWrapper/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

plugins {
id("java-library")
Expand Down Expand Up @@ -50,31 +51,43 @@ jar {
processResources {
// disable cache
outputs.upToDateWhen { false }
ArrayList<?> mc_condition = []
ArrayList<?> jars = []

fabric_subprojects.each({
mc_condition.add("${it.minecraft_dependency}")
jars.add(["file": "META-INF/jars/${project.mod_archives_base_name}-${it.minecraft_version}-${project.version}.jar"])
})

from("${rootDir}/icon.png") {
into("assets/${project.mod_id}")
}

filesMatching("fabric.mod.json") {
expand([
"minecraft_dependency": new JsonBuilder(mc_condition),
"mod_description" : project.mod_description,
"mod_homepage" : project.mod_homepage,
"mod_id" : project.mod_id,
"mod_license" : project.mod_license,
"mod_name" : project.mod_name,
"mod_version" : project.getModVersion(),
"mod_sources" : project.mod_sources,
"sub_jars" : new JsonBuilder(jars).toPrettyString(),
])
}

doLast {
ArrayList<?> mc_condition = []
ArrayList<?> jars = []

fabric_subprojects.each({
mc_condition.add("${it.minecraft_dependency}")
jars.add(["file": "META-INF/jars/${project.mod_archives_base_name}-${it.minecraft_version}-${project.version}.jar"])
})

File file = file("build/resources/main/fabric.mod.json")
JsonSlurper slurper = new JsonSlurper()
JsonBuilder builder = new JsonBuilder(slurper.parse(file))
builder.content.depends.minecraft = mc_condition
builder.content.jars = jars
BufferedWriter writer = file.newWriter()
writer.append(builder.toPrettyString())
writer.flush()
writer.close()
println builder.toPrettyString()
}
}

java {
Expand Down Expand Up @@ -162,4 +175,4 @@ signing {
TaskCollection<Sign> signingTasks = tasks.withType(Sign)
tasks.withType(AbstractPublishToMaven).configureEach {
it.dependsOn(signingTasks)
}
}
6 changes: 2 additions & 4 deletions fabricWrapper/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
}
},
"depends": {
"fabricloader": ">=0.11.7",
"minecraft": ${minecraft_dependency}
},
"jars": ${sub_jars}
"fabricloader": ">=0.11.7"
}
}

0 comments on commit fadc597

Please sign in to comment.