[build, minecraft] Publishing as Minecraft Fabric mods

This commit is contained in:
2025-08-03 15:58:55 +02:00
parent b5263c7a5c
commit f694672d5f
17 changed files with 251 additions and 3 deletions

View File

@@ -5,3 +5,7 @@ plugins {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
} }
dependencies {
implementation(project(":helpers"))
}

View File

@@ -0,0 +1,15 @@
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
repositories {
gradlePluginPortal()
}
gradlePlugin {
plugins.register("minecraftModComponent") {
id = "de.siphalor.tweed5.minecraft.mod.component"
implementationClass = "de.siphalor.tweed5.gradle.plugin.minecraft.mod.MinecraftModComponentPlugin"
}
}

View File

@@ -0,0 +1,64 @@
package de.siphalor.tweed5.gradle.plugin.minecraft.mod
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Category
import org.gradle.api.attributes.DocsType
import org.gradle.api.attributes.LibraryElements
import org.gradle.api.attributes.Usage
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.component.SoftwareComponentFactory
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.named
import javax.inject.Inject
abstract class MinecraftModComponentPlugin : Plugin<Project> {
@get:Inject
abstract val softwareComponentFactory: SoftwareComponentFactory
@get:Inject
abstract val objectFactory: ObjectFactory
override fun apply(project: Project) {
val modComponent = softwareComponentFactory.adhoc("minecraftMod")
project.components.add(modComponent)
val targetJvmVersion = project.tasks.named<JavaCompile>("compileJava")
.map { JavaVersion.toVersion(it.targetCompatibility).majorVersion }
val modElementsConfiguration = project.configurations.consumable("minecraftModElements") {
attributes {
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_RUNTIME))
project.afterEvaluate {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJvmVersion.get().toInt())
}
}
}
val apiConfiguration = project.configurations.named("api")
val modSourcesElementsConfiguration = project.configurations.consumable("minecraftModSourcesElements") {
extendsFrom(apiConfiguration.get())
attributes {
attribute(MinecraftModded.MINECRAFT_MODDED_ATTRIBUTE, objectFactory.named(MinecraftModded.MODDED))
attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objectFactory.named(DocsType.SOURCES))
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EXTERNAL))
}
}
modComponent.addVariantsFromConfiguration(modElementsConfiguration.get()) {
mapToMavenScope("runtime")
}
modComponent.addVariantsFromConfiguration(modSourcesElementsConfiguration.get()) {
mapToOptional()
}
}
}

View File

@@ -0,0 +1,12 @@
package de.siphalor.tweed5.gradle.plugin.minecraft.mod
import org.gradle.api.Named
import org.gradle.api.attributes.Attribute
interface MinecraftModded : Named {
companion object {
val MINECRAFT_MODDED_ATTRIBUTE = Attribute.of("de.siphalor.tweed5.minecraft.modded", MinecraftModded::class.java)
const val PLAIN = "plain"
const val MODDED = "modded"
}
}

View File

@@ -2,4 +2,6 @@ plugins {
id("dev.panuszewski.typesafe-conventions") version "0.7.3" id("dev.panuszewski.typesafe-conventions") version "0.7.3"
} }
include("helpers")
rootProject.name = "tweed5-conventions" rootProject.name = "tweed5-conventions"

View File

@@ -73,7 +73,7 @@ tasks.test {
publishing { publishing {
publications { publications {
create<MavenPublication>("maven") { create<MavenPublication>("lib") {
groupId = project.group.toString() groupId = project.group.toString()
artifactId = project.name artifactId = project.name
version = project.version.toString() version = project.version.toString()

View File

@@ -8,6 +8,8 @@ plugins {
val expandedSourcesElements = configurations.consumable("expandedSourcesElements") { val expandedSourcesElements = configurations.consumable("expandedSourcesElements") {
attributes { attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
} }
} }
@@ -15,6 +17,8 @@ val expandedSourcesElements = configurations.consumable("expandedSourcesElements
val delombok = tasks.getByName<Delombok>("delombok") val delombok = tasks.getByName<Delombok>("delombok")
val sourcesJar by tasks.registering(Jar::class) { val sourcesJar by tasks.registering(Jar::class) {
group = LifecycleBasePlugin.BUILD_GROUP
dependsOn(delombok) dependsOn(delombok)
from(delombok.target) from(delombok.target)
archiveClassifier.set("sources") archiveClassifier.set("sources")

View File

@@ -0,0 +1,46 @@
plugins {
`maven-publish`
alias(libs.plugins.shadow)
id("de.siphalor.tweed5.expanded-sources-jar")
id("de.siphalor.tweed5.minecraft.mod.component")
}
tasks.shadowJar {
relocate("org.apache.commons", "de.siphalor.tweed5.shadowed.org.apache.commons")
}
val minecraftModJar = tasks.register<Jar>("minecraftModJar") {
group = LifecycleBasePlugin.BUILD_GROUP
from(zipTree(tasks.shadowJar.get().archiveFile))
destinationDirectory.set(layout.buildDirectory.dir("minecraftModLibs"))
}
tasks.assemble {
dependsOn(minecraftModJar)
}
val minecraftModSourcesJar = tasks.register<Jar>("minecraftModSourcesJar") {
group = LifecycleBasePlugin.BUILD_GROUP
from(zipTree(tasks.named<Jar>("sourcesJar").get().archiveFile))
archiveClassifier = "sources"
destinationDirectory.set(layout.buildDirectory.dir("minecraftModLibs"))
}
artifacts.add("minecraftModElements", minecraftModJar)
artifacts.add("minecraftModSourcesElements", minecraftModSourcesJar)
publishing {
publications {
create<MavenPublication>("minecraftMod") {
groupId = "${project.group}.minecraft"
artifactId = project.name
version = project.version.toString()
from(components["minecraftMod"])
}
}
}

View File

@@ -0,0 +1,25 @@
plugins {
java
id("de.siphalor.tweed5.minecraft.mod.base")
}
val processMinecraftModResources = tasks.register<Copy>("processMinecraftModResources") {
from(project.layout.settingsDirectory.dir("minecraft/mod-template/resources"))
expand(
"id" to project.name,
"version" to project.version,
"name" to properties["minecraft.mod.name"],
"description" to properties["minecraft.mod.description"]
)
into(project.layout.buildDirectory.dir("minecraftModResources"))
}
tasks.named<Jar>("minecraftModJar") {
from(project.layout.buildDirectory.dir("minecraftModResources"))
dependsOn(processMinecraftModResources)
}
tasks.named<Jar>("minecraftModSourcesJar") {
from(project.layout.buildDirectory.dir("minecraftModResources"))
dependsOn(processMinecraftModResources)
}

View File

@@ -11,10 +11,12 @@ junit = "5.12.0"
lombok = "1.18.38" lombok = "1.18.38"
logback = "1.5.18" logback = "1.5.18"
mockito = "5.14.2" mockito = "5.14.2"
shadow = "9.0.0-rc2"
slf4j = "2.0.16" slf4j = "2.0.16"
[plugins] [plugins]
lombok = { id = "io.freefair.lombok", version = "8.13.1" } lombok = { id = "io.freefair.lombok", version = "8.13.1" }
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
[libraries] [libraries]
acl = { group = "commons-logging", name = "commons-logging", version.ref = "acl" } acl = { group = "commons-logging", name = "commons-logging", version.ref = "acl" }

View File

@@ -0,0 +1,37 @@
{
"schemaVersion": 1,
"license": "LGPL-3.0-only",
"contact": {
"email": "info@siphalor.de",
"issues": "https://gitea.siphalor.de/Siphalor/tweed5/issues",
"sources": "https://gitea.siphalor.de/Siphalor/tweed5"
},
"custom": {
"modmenu": {
"badges": [
"library"
],
"links": {
"modmenu.discord": "https://discord.gg/6gaXmbj"
},
"parent": {
"id": "tweed5",
"name": "Tweed 5",
"description": "Configuration focused libraries",
"icon": "assets/tweed4_base/icon.png",
"badges": [
"library"
]
}
},
"modmenu:api": true
},
"icon": "assets/tweed5/icon.png",
"id": "${id}",
"name": "${name}",
"description": "${description}",
"authors": [
"Siphalor"
],
"version": "${version}"
}

View File

@@ -0,0 +1,20 @@
plugins {
`maven-publish`
id("de.siphalor.tweed5.base-module")
id("de.siphalor.tweed5.minecraft.mod.dummy")
}
dependencies {
implementation(project(":tweed5-core"))
implementation(project(":tweed5-attributes-extension"))
implementation(project(":tweed5-default-extensions"))
implementation(project(":tweed5-serde-extension"))
implementation(project(":tweed5-weaver-pojo"))
implementation(project(":tweed5-weaver-pojo-attributes-extension"))
implementation(project(":tweed5-weaver-pojo-serde-extension"))
implementation(project(":tweed5-weaver-pojo-validation-extension"))
}
tasks.shadowJar {
relocate("org.objectweb.asm", "de.siphalor.tweed5.shadowed.org.objectweb.asm")
}

View File

@@ -0,0 +1,3 @@
minecraft.mod.name = Tweed 5 Bundle
minecraft.mod.description = Bundle of pre-packaged Tweed modules \
that are usually required for your Minecraft mod config needs.

View File

@@ -17,3 +17,10 @@ include("tweed5-weaver-pojo")
include("tweed5-weaver-pojo-attributes-extension") include("tweed5-weaver-pojo-attributes-extension")
include("tweed5-weaver-pojo-serde-extension") include("tweed5-weaver-pojo-serde-extension")
include("tweed5-weaver-pojo-validation-extension") include("tweed5-weaver-pojo-validation-extension")
includeAs("minecraft:tweed5-bundle", "minecraft/tweed5-bundle")
fun includeAs(name: String, path: String) {
include(name)
project(":$name").projectDir = file(path)
}

View File

@@ -1,7 +1,12 @@
plugins { plugins {
id("de.siphalor.tweed5.base-module") id("de.siphalor.tweed5.base-module")
id("de.siphalor.tweed5.minecraft.mod.dummy")
} }
dependencies { dependencies {
api(project(":tweed5-serde-api")) api(project(":tweed5-serde-api"))
} }
tasks.shadowJar {
configurations = setOf()
}

View File

@@ -0,0 +1,2 @@
minecraft.mod.name = Tweed 5 Hjson
minecraft.mod.description = Tweed 5 module that supports the Hjson file format.