[build] Restructure to composite build

This commit is contained in:
2025-10-26 02:03:53 +02:00
parent 0e3990aed9
commit 1fbc97866c
348 changed files with 126 additions and 64 deletions

View File

@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}
dependencies {
implementation(project(":helpers"))
}

View File

@@ -0,0 +1,11 @@
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
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

@@ -0,0 +1,18 @@
plugins {
id("dev.panuszewski.typesafe-conventions") version "0.9.0"
}
dependencyResolutionManagement {
repositories {
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
include("helpers")
rootProject.name = "tweed5-conventions"

View File

@@ -0,0 +1,84 @@
plugins {
java
`java-library`
jacoco
alias(libs.plugins.lombok)
id("de.siphalor.tweed5.publishing")
id("de.siphalor.tweed5.local-runtime-only")
id("de.siphalor.tweed5.expanded-sources-jar")
}
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.main.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.java.main.get())
}
val testAgent = configurations.dependencyScope("mockitoAgent")
val testAgentClasspath = configurations.resolvable("testAgentClasspath") {
isTransitive = false
extendsFrom(testAgent.get())
}
lombok {
version = libs.versions.lombok.get()
}
dependencies {
compileOnly(libs.autoservice.annotations)
annotationProcessor(libs.autoservice.processor)
testCompileOnly(libs.autoservice.annotations)
testAnnotationProcessor(libs.autoservice.processor)
compileOnly(libs.jetbrains.annotations)
testImplementation(libs.jetbrains.annotations)
compileOnly(libs.jspecify.annotations)
testImplementation(libs.jspecify.annotations)
implementation(libs.acl)
"localRuntimeOnly"(libs.slf4j.rt)
testImplementation(libs.acl)
testImplementation(libs.slf4j.rt)
testImplementation(platform(libs.junit.platform))
testImplementation(libs.junit.core)
testRuntimeOnly(libs.junit.launcher)
testImplementation(libs.mockito)
testAgent(libs.mockito)
testImplementation(libs.assertj)
testImplementation(project(":generic-test-utils"))
}
tasks.compileTestJava {
sourceCompatibility = libs.versions.java.test.get()
targetCompatibility = libs.versions.java.test.get()
}
tasks.test {
dependsOn(testAgentClasspath)
finalizedBy(tasks.jacocoTestReport)
useJUnitPlatform()
jvmArgs(testAgentClasspath.get().files.map { file -> "-javaagent:${file.absolutePath}" })
systemProperties(
"junit.jupiter.execution.timeout.mode" to "disabled_on_debug",
"junit.jupiter.execution.timeout.testable.method.default" to "10s",
"junit.jupiter.execution.timeout.thread.mode.default" to "SEPARATE_THREAD",
)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
}
publishing {
publications {
create<MavenPublication>("lib") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
}
}
}

View File

@@ -0,0 +1,34 @@
import io.freefair.gradle.plugins.lombok.tasks.Delombok
plugins {
java
`java-library`
alias(libs.plugins.lombok)
}
val expandedSourcesElements = configurations.consumable("expandedSourcesElements") {
extendsFrom(configurations.implementation.get())
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))
}
}
val delombok = tasks.getByName<Delombok>("delombok")
val sourcesJar by tasks.registering(Jar::class) {
group = LifecycleBasePlugin.BUILD_GROUP
dependsOn(delombok)
from(delombok.target)
archiveClassifier.set("sources")
}
artifacts.add(expandedSourcesElements.name, sourcesJar)
tasks.named("build") { dependsOn(sourcesJar) }
components.named<AdhocComponentWithVariants>("java") {
addVariantsFromConfiguration(expandedSourcesElements.get()) {}
}

View File

@@ -0,0 +1,6 @@
plugins {
java
}
val localRuntimeOnly = configurations.create("localRuntimeOnly")
sourceSets.main.get().runtimeClasspath += localRuntimeOnly

View File

@@ -0,0 +1,47 @@
plugins {
`maven-publish`
alias(libs.plugins.shadow)
java
`java-library`
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,29 @@
plugins {
id("de.siphalor.tweed5.minecraft.mod.base")
}
val processMinecraftModResources = tasks.register<Copy>("processMinecraftModResources") {
inputs.property("id", project.name)
inputs.property("version", project.version)
inputs.property("name", properties["module.name"])
inputs.property("description", properties["module.description"])
from(project.layout.settingsDirectory.dir("../tweed5-minecraft/mod-template/resources"))
expand(mapOf(
"id" to project.name,
"version" to project.version,
"name" to properties["module.name"],
"description" to properties["module.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

@@ -0,0 +1,35 @@
plugins {
`java-library`
`maven-publish`
}
group = rootProject.group
version = rootProject.version
publishing {
repositories {
if (project.hasProperty("siphalor.maven.user")) {
maven {
name = "Siphalor"
url = uri("https://maven.siphalor.de/upload.php")
credentials {
username = project.property("siphalor.maven.user") as String
password = project.property("siphalor.maven.password") as String
}
}
}
}
publications.all {
if (this is MavenPublication) {
pom {
name = project.property("module.name") as String
description = project.property("module.description") as String
url = project.property("git.url") as String
scm {
url = project.property("git.url") as String
}
}
}
}
}

View File

@@ -0,0 +1,5 @@
import java.util.Properties
val rootProperties = Properties()
project.layout.settingsDirectory.file("../gradle.properties").asFile.inputStream().use { rootProperties.load(it) }
rootProperties.forEach { (key, value) -> project.ext.set(key.toString(), value.toString()) }

View File

@@ -0,0 +1,14 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
alias(libs.plugins.shadow)
}
val shadowOnlyConfiguration = configurations.dependencyScope("shadowOnly")
val shadowOnlyElementsConfiguration = configurations.resolvable("shadowOnlyElements") {
extendsFrom(shadowOnlyConfiguration.get())
}
tasks.named<ShadowJar>("shadowJar") {
configurations = listOf(shadowOnlyElementsConfiguration.get())
}

View File

@@ -0,0 +1,21 @@
plugins {
java
alias(libs.plugins.lombok)
}
dependencies {
implementation(project(":tweed5-serde-api"))
implementation(platform(libs.junit.platform))
implementation(libs.junit.core)
implementation(libs.mockito)
implementation(libs.assertj)
}
lombok {
version = libs.versions.lombok.get()
}
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.test.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.java.test.get())
}