feat(minecraft): Make every subproject its own mod

This commit is contained in:
2025-11-08 00:44:52 +01:00
parent 47ad406560
commit d2dada2b77
34 changed files with 186 additions and 65 deletions

View File

@@ -34,7 +34,7 @@ abstract class MinecraftModComponentPlugin : Plugin<Project> {
attribute(MinecraftModded.MINECRAFT_MODDED_ATTRIBUTE, objectFactory.named(MinecraftModded.MODDED))
attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.LIBRARY))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.JAR))
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.SHADOWED))
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EMBEDDED))
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_RUNTIME))
project.afterEvaluate {
@@ -48,8 +48,8 @@ abstract class MinecraftModComponentPlugin : Plugin<Project> {
attribute(MinecraftModded.MINECRAFT_MODDED_ATTRIBUTE, objectFactory.named(MinecraftModded.MODDED))
attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.LIBRARY))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.JAR))
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.SHADOWED))
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_API))
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EXTERNAL))
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_RUNTIME))
project.afterEvaluate {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJvmVersion.get().toInt())

View File

@@ -2,6 +2,7 @@ plugins {
id("com.gradleup.shadow")
java
`java-library`
id("de.siphalor.tweed5.shadow.explicit")
id("de.siphalor.tweed5.minecraft.mod.component")
}
@@ -10,16 +11,25 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}
val minecraftJijElements = configurations.resolvable("minecraftJijElements")
tasks.shadowJar {
relocate("org.apache.commons", "de.siphalor.tweed5.shadowed.org.apache.commons")
}
fun formatJarsForJson(jars: FileCollection): String {
return jars.files.joinToString(",") { "{\"file\":\"META-INF/jars/${it.name}\"}"}
}
tasks.register<Sync>("processMinecraftModResources") {
inputs.property("id", project.name)
inputs.property("version", project.version)
inputs.property("name", properties["module.name"])
inputs.property("description", properties["module.description"])
inputs.property("repoUrl", properties["git.url"])
inputs.files(minecraftJijElements)
val jars = objects.fileCollection().apply { from(minecraftJijElements) }
from(project.layout.settingsDirectory.dir("../tweed5-minecraft/mod-template/resources")) {
expand(
@@ -29,6 +39,7 @@ tasks.register<Sync>("processMinecraftModResources") {
"name" to properties["module.name"],
"description" to properties["module.description"],
"repoUrl" to properties["git.url"],
"jars" to formatJarsForJson(jars)
)
)
}
@@ -44,6 +55,9 @@ tasks.register<Sync>("processMinecraftTestmodResources") {
inputs.property("name", properties["module.name"])
inputs.property("description", properties["module.description"])
inputs.property("repoUrl", properties["git.url"])
inputs.files(minecraftJijElements)
val jars = objects.fileCollection().apply { from(minecraftJijElements) }
from(project.layout.settingsDirectory.dir("../tweed5-minecraft/mod-template/resources")) {
expand(
@@ -53,6 +67,7 @@ tasks.register<Sync>("processMinecraftTestmodResources") {
"name" to "${properties["module.name"]} (test mod)",
"description" to properties["module.description"],
"repoUrl" to properties["git.url"],
"jars" to formatJarsForJson(jars)
)
)
}

View File

@@ -4,6 +4,11 @@ plugins {
id("de.siphalor.tweed5.minecraft.mod.base")
}
configurations.minecraftModApiElements {
extendsFrom(configurations.implementation.get())
exclude("commons-logging", "commons-logging")
}
val minecraftModJar = tasks.register<Jar>("minecraftModJar") {
group = LifecycleBasePlugin.BUILD_GROUP
@@ -25,13 +30,10 @@ val minecraftModSourcesJar = tasks.register<Jar>("minecraftModSourcesJar") {
dependsOn(tasks.named("sourcesJar"))
dependsOn(tasks.named("processMinecraftModResources"))
from(tasks.named<Jar>("sourcesJar").get().archiveFile.map {
if (it.asFile.exists()) {
zipTree(it)
} else {
files()
}
})
val sourcesJar = objects.fileCollection().from(tasks.named<Jar>("sourcesJar").map { it.archiveFile })
inputs.files(sourcesJar)
from(sourcesJar.map { zipTree(it) })
from(project.layout.buildDirectory.dir("minecraftModResources"))
archiveClassifier = "sources"