diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 8156a89..84492e6 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,4 +4,8 @@ plugins { repositories { gradlePluginPortal() -} \ No newline at end of file +} + +dependencies { + implementation(project(":helpers")) +} diff --git a/buildSrc/helpers/build.gradle.kts b/buildSrc/helpers/build.gradle.kts new file mode 100644 index 0000000..bf7b9ab --- /dev/null +++ b/buildSrc/helpers/build.gradle.kts @@ -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" + } +} diff --git a/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModComponentPlugin.kt b/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModComponentPlugin.kt new file mode 100644 index 0000000..b2b545f --- /dev/null +++ b/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModComponentPlugin.kt @@ -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 { + @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("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() + } + } +} diff --git a/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModded.kt b/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModded.kt new file mode 100644 index 0000000..f90d3ab --- /dev/null +++ b/buildSrc/helpers/src/main/kotlin/de/siphalor/tweed5/gradle/plugin/minecraft/mod/MinecraftModded.kt @@ -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" + } +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index b4881a3..bc7d0dc 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -2,4 +2,6 @@ plugins { id("dev.panuszewski.typesafe-conventions") version "0.7.3" } +include("helpers") + rootProject.name = "tweed5-conventions" diff --git a/buildSrc/src/main/kotlin/de.siphalor.tweed5.base-module.gradle.kts b/buildSrc/src/main/kotlin/de.siphalor.tweed5.base-module.gradle.kts index 1b878b5..126711e 100644 --- a/buildSrc/src/main/kotlin/de.siphalor.tweed5.base-module.gradle.kts +++ b/buildSrc/src/main/kotlin/de.siphalor.tweed5.base-module.gradle.kts @@ -73,7 +73,7 @@ tasks.test { publishing { publications { - create("maven") { + create("lib") { groupId = project.group.toString() artifactId = project.name version = project.version.toString() diff --git a/buildSrc/src/main/kotlin/de.siphalor.tweed5.expanded-sources-jar.gradle.kts b/buildSrc/src/main/kotlin/de.siphalor.tweed5.expanded-sources-jar.gradle.kts index 7169c17..f698b76 100644 --- a/buildSrc/src/main/kotlin/de.siphalor.tweed5.expanded-sources-jar.gradle.kts +++ b/buildSrc/src/main/kotlin/de.siphalor.tweed5.expanded-sources-jar.gradle.kts @@ -8,6 +8,8 @@ plugins { val expandedSourcesElements = configurations.consumable("expandedSourcesElements") { 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)) } } @@ -15,6 +17,8 @@ val expandedSourcesElements = configurations.consumable("expandedSourcesElements val delombok = tasks.getByName("delombok") val sourcesJar by tasks.registering(Jar::class) { + group = LifecycleBasePlugin.BUILD_GROUP + dependsOn(delombok) from(delombok.target) archiveClassifier.set("sources") diff --git a/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.base.gradle.kts b/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.base.gradle.kts new file mode 100644 index 0000000..2587798 --- /dev/null +++ b/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.base.gradle.kts @@ -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("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("minecraftModSourcesJar") { + group = LifecycleBasePlugin.BUILD_GROUP + + from(zipTree(tasks.named("sourcesJar").get().archiveFile)) + + archiveClassifier = "sources" + destinationDirectory.set(layout.buildDirectory.dir("minecraftModLibs")) +} + +artifacts.add("minecraftModElements", minecraftModJar) +artifacts.add("minecraftModSourcesElements", minecraftModSourcesJar) + +publishing { + publications { + create("minecraftMod") { + groupId = "${project.group}.minecraft" + artifactId = project.name + version = project.version.toString() + + from(components["minecraftMod"]) + } + } +} + diff --git a/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.dummy.gradle.kts b/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.dummy.gradle.kts new file mode 100644 index 0000000..38ff9b3 --- /dev/null +++ b/buildSrc/src/main/kotlin/de.siphalor.tweed5.minecraft.mod.dummy.gradle.kts @@ -0,0 +1,25 @@ +plugins { + java + id("de.siphalor.tweed5.minecraft.mod.base") +} + +val processMinecraftModResources = tasks.register("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("minecraftModJar") { + from(project.layout.buildDirectory.dir("minecraftModResources")) + dependsOn(processMinecraftModResources) +} + +tasks.named("minecraftModSourcesJar") { + from(project.layout.buildDirectory.dir("minecraftModResources")) + dependsOn(processMinecraftModResources) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc471cd..e735e81 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,10 +11,12 @@ junit = "5.12.0" lombok = "1.18.38" logback = "1.5.18" mockito = "5.14.2" +shadow = "9.0.0-rc2" slf4j = "2.0.16" [plugins] lombok = { id = "io.freefair.lombok", version = "8.13.1" } +shadow = { id = "com.gradleup.shadow", version.ref = "shadow" } [libraries] acl = { group = "commons-logging", name = "commons-logging", version.ref = "acl" } diff --git a/minecraft/mod-template/resources/fabric.mod.json b/minecraft/mod-template/resources/fabric.mod.json new file mode 100644 index 0000000..ef8e044 --- /dev/null +++ b/minecraft/mod-template/resources/fabric.mod.json @@ -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}" +} diff --git a/minecraft/tweed5-bundle/build.gradle.kts b/minecraft/tweed5-bundle/build.gradle.kts new file mode 100644 index 0000000..8480802 --- /dev/null +++ b/minecraft/tweed5-bundle/build.gradle.kts @@ -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") +} diff --git a/minecraft/tweed5-bundle/gradle.properties b/minecraft/tweed5-bundle/gradle.properties new file mode 100644 index 0000000..ca4cc24 --- /dev/null +++ b/minecraft/tweed5-bundle/gradle.properties @@ -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. diff --git a/minecraft/tweed5-bundle/src/main/resources/assets/tweed5/icon.png b/minecraft/tweed5-bundle/src/main/resources/assets/tweed5/icon.png new file mode 100644 index 0000000..e69de29 diff --git a/settings.gradle.kts b/settings.gradle.kts index cd46f2f..6f46cc0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,3 +17,10 @@ include("tweed5-weaver-pojo") include("tweed5-weaver-pojo-attributes-extension") include("tweed5-weaver-pojo-serde-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) +} diff --git a/tweed5-serde-hjson/build.gradle.kts b/tweed5-serde-hjson/build.gradle.kts index 4767606..ccaea05 100644 --- a/tweed5-serde-hjson/build.gradle.kts +++ b/tweed5-serde-hjson/build.gradle.kts @@ -1,7 +1,12 @@ plugins { id("de.siphalor.tweed5.base-module") + id("de.siphalor.tweed5.minecraft.mod.dummy") } dependencies { api(project(":tweed5-serde-api")) -} \ No newline at end of file +} + +tasks.shadowJar { + configurations = setOf() +} diff --git a/tweed5-serde-hjson/gradle.properties b/tweed5-serde-hjson/gradle.properties new file mode 100644 index 0000000..d10f6c8 --- /dev/null +++ b/tweed5-serde-hjson/gradle.properties @@ -0,0 +1,2 @@ +minecraft.mod.name = Tweed 5 Hjson +minecraft.mod.description = Tweed 5 module that supports the Hjson file format.