From becad4e18415b4366d593f8f441ec285d16dc2f1 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:13:08 -0700 Subject: [PATCH] move common gradle project configuration to conventions plugin --- build.gradle.kts | 122 +++--------------- buildSrc/build.gradle.kts | 18 +++ .../xaeroplus-all.conventions.gradle.kts | 42 ++++++ .../xaeroplus-platform.conventions.gradle.kts | 49 +++++++ common/build.gradle.kts | 16 ++- fabric/build.gradle.kts | 5 + forge/build.gradle.kts | 10 ++ settings.gradle.kts | 2 - 8 files changed, 156 insertions(+), 108 deletions(-) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/xaeroplus-all.conventions.gradle.kts create mode 100644 buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 852b17ca..04433472 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,124 +1,44 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import net.fabricmc.loom.api.LoomGradleExtensionAPI - plugins { - id("architectury-plugin") version "3.4-SNAPSHOT" - id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false - id("com.gradleup.shadow") version "8.3.2" apply false + id("xaeroplus-all.conventions") idea } val minecraft_version: String by gradle.extra -val mc = libs.minecraft.get() -val parchment = libs.parchment.get() architectury { minecraft = minecraft_version } -subprojects { - apply(plugin = "dev.architectury.loom") - apply(plugin = "com.gradleup.shadow") - - configure { - silentMojangMappingsLicense() - runs { - getByName("client") { - programArgs("--username", "rfresh2") - } - } - } - - dependencies { - "minecraft"(mc) - "mappings"((project.extensions.getByType(LoomGradleExtensionAPI::class)).layered { - officialMojangMappings() - parchment(parchment) - }) - } - - tasks { - getByName("shadowJar") { - archiveClassifier.set("shadow") - exclude("com/google/**") - exclude("org/objectweb/**") - exclude("org/checkerframework/**") - exclude("org/rfresh/sqlite/native/FreeBSD/**") - exclude("org/rfresh/sqlite/native/Linux-Android/**") - exclude("org/rfresh/sqlite/native/Linux-Musl/**") - exclude("org/rfresh/sqlite/native/Linux/arm/**") - exclude("org/rfresh/sqlite/native/Linux/aarch64/**") - exclude("org/rfresh/sqlite/native/Linux/armv6/**") - exclude("org/rfresh/sqlite/native/Linux/x86/**") - exclude("org/rfresh/sqlite/native/Linux/armv7/**") - exclude("org/rfresh/sqlite/native/Linux/ppc64/**") - exclude("org/rfresh/sqlite/native/Linux/riscv64/**") - exclude("org/rfresh/sqlite/native/Windows/armv7/**") - exclude("org/rfresh/sqlite/native/Windows/aarch64/**") - exclude("org/rfresh/sqlite/native/Windows/armv7/**") - exclude("org/slf4j/**") - } - } -} - -allprojects { - apply(plugin = "java") - apply(plugin = "architectury-plugin") - apply(plugin = "maven-publish") - - configure { - archivesName = gradle.extra.get("archives_base_name").toString() - } - - version = gradle.extra.get("mod_version").toString() - group = gradle.extra.get("maven_group").toString() - - repositories { - maven("https://api.modrinth.com/maven") { - name = "Modrinth" - } - maven("https://maven.2b2t.vc/releases") { - name = "maven.2b2t.vc" - } - maven("https://maven.parchmentmc.org") { - name = "ParchmentMC" - } - maven("https://maven.lenni0451.net/releases") { - name = "Lenni0451" - } - maven("https://maven.shedaniel.me/") - maven("https://maven.terraformersmc.com/releases/") - mavenLocal() - } - - tasks { - withType { - options.encoding = "UTF-8" - options.release = 17 - } - } - - configure { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } -} - tasks { register("printWorldMapVersionFabric") { - println(gradle.extra.get("worldmap_version_fabric")) + doLast { + println(gradle.extra.get("worldmap_version_fabric")) + } + outputs.upToDateWhen { false } } register("printMinimapVersionFabric") { - println(gradle.extra.get("minimap_version_fabric")) + doLast { + println(gradle.extra.get("minimap_version_fabric")) + } + outputs.upToDateWhen { false } } register("printWorldMapVersionForge") { - println(gradle.extra.get("worldmap_version_forge")) + doLast { + println(gradle.extra.get("worldmap_version_forge")) + } + outputs.upToDateWhen { false } } register("printMinimapVersionForge") { - println(gradle.extra.get("minimap_version_forge")) + doLast { + println(gradle.extra.get("minimap_version_forge")) + } + outputs.upToDateWhen { false } } register("printXaeroPlusVersion") { - println(version) + doLast { + println(version) + } + outputs.upToDateWhen { false } } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..6e42c039 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + `kotlin-dsl` +} + +repositories { + maven("https://maven.fabricmc.net/") { name = "Fabric" } + maven("https://maven.architectury.dev/") + maven("https://files.minecraftforge.net/maven/") + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation("architectury-plugin:architectury-plugin.gradle.plugin:3.4-SNAPSHOT") + implementation("dev.architectury:architectury-loom:1.7-SNAPSHOT") + implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.3") +} + diff --git a/buildSrc/src/main/kotlin/xaeroplus-all.conventions.gradle.kts b/buildSrc/src/main/kotlin/xaeroplus-all.conventions.gradle.kts new file mode 100644 index 00000000..8b82d19a --- /dev/null +++ b/buildSrc/src/main/kotlin/xaeroplus-all.conventions.gradle.kts @@ -0,0 +1,42 @@ +plugins { + java + id("maven-publish") + id("architectury-plugin") +} + +configure { + archivesName = "XaeroPlus" +} + +version = gradle.extra.get("mod_version").toString() +group = gradle.extra.get("maven_group").toString() + +repositories { + maven("https://api.modrinth.com/maven") { + name = "Modrinth" + } + maven("https://maven.2b2t.vc/releases") { + name = "maven.2b2t.vc" + } + maven("https://maven.parchmentmc.org") { + name = "ParchmentMC" + } + maven("https://maven.lenni0451.net/releases") { + name = "Lenni0451" + } + maven("https://maven.shedaniel.me/") + maven("https://maven.terraformersmc.com/releases/") + mavenLocal() +} + +tasks { + withType { + options.encoding = "UTF-8" + options.release = 17 + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} diff --git a/buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts b/buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts new file mode 100644 index 00000000..49a83aed --- /dev/null +++ b/buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts @@ -0,0 +1,49 @@ +plugins { + id("dev.architectury.loom") + id("com.gradleup.shadow") +} + +loom { + silentMojangMappingsLicense() + runs { + getByName("client") { + programArgs("--username", "rfresh2") + } + } +} + +val minecraft_version: String by gradle.extra +val parchment_version: String by gradle.extra +val mc = "com.mojang:minecraft:${minecraft_version}" +val parchment = "org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}" + +dependencies { + minecraft(mc) + mappings(loom.layered { + officialMojangMappings() + parchment(parchment) + }) +} + +tasks { + shadowJar { + archiveClassifier.set("shadow") + exclude("com/google/**") + exclude("org/objectweb/**") + exclude("org/checkerframework/**") + exclude("org/rfresh/sqlite/native/FreeBSD/**") + exclude("org/rfresh/sqlite/native/Linux-Android/**") + exclude("org/rfresh/sqlite/native/Linux-Musl/**") + exclude("org/rfresh/sqlite/native/Linux/arm/**") + exclude("org/rfresh/sqlite/native/Linux/aarch64/**") + exclude("org/rfresh/sqlite/native/Linux/armv6/**") + exclude("org/rfresh/sqlite/native/Linux/x86/**") + exclude("org/rfresh/sqlite/native/Linux/armv7/**") + exclude("org/rfresh/sqlite/native/Linux/ppc64/**") + exclude("org/rfresh/sqlite/native/Linux/riscv64/**") + exclude("org/rfresh/sqlite/native/Windows/armv7/**") + exclude("org/rfresh/sqlite/native/Windows/aarch64/**") + exclude("org/rfresh/sqlite/native/Windows/armv7/**") + exclude("org/slf4j/**") + } +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 396612d6..32d3c226 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,3 +1,10 @@ +import kotlin.streams.asStream + +plugins { + id("xaeroplus-all.conventions") + id("xaeroplus-platform.conventions") +} + architectury { common(rootProject.properties["enabled_platforms"].toString().split(",")) } @@ -22,14 +29,14 @@ dependencies { } tasks { - val remapForgeTask = register("remapForge") { + register("remapForge") { group = "build" description = "Remap the source files, replacing fabric-specific strings with forge-specific strings." + val remapDir = project.layout.buildDirectory.dir("remappedSources/forge").get().asFile doLast { - val remapDir = file("build/remappedSources/forge") // clear directory if it exists if (remapDir.exists()) { - remapDir.delete() + remapDir.deleteRecursively() } remapDir.mkdirs() // create sourceset directory structure @@ -62,7 +69,7 @@ tasks { } // exec remap on every source file - remapDir.walk().forEach { file -> + remapDir.walk().asStream().parallel().forEach { file -> if (file.isFile && (file.extension == "java" || file.extension == "json")) { var text = file.readText() remap.forEach { (fabric, forge) -> @@ -73,6 +80,5 @@ tasks { } } } - compileJava.get().dependsOn(remapForgeTask) } diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index c948e8db..d5e0205e 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -1,3 +1,8 @@ +plugins { + id("xaeroplus-all.conventions") + id("xaeroplus-platform.conventions") +} + architectury { platformSetupLoomIde() fabric() diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index d5f63cb4..dceaf779 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -4,6 +4,11 @@ import dev.architectury.transformer.transformers.FixForgeMixin import dev.architectury.transformer.transformers.TransformForgeAnnotations import dev.architectury.transformer.transformers.TransformForgeEnvironment +plugins { + id("xaeroplus-all.conventions") + id("xaeroplus-platform.conventions") +} + architectury { platformSetupLoomIde() forge() @@ -57,6 +62,7 @@ dependencies { tasks { processResources { + dependsOn(common.tasks.getByName("remapForge")) filesMatching("META-INF/mods.toml") { expand(mapOf( "version" to project.version, @@ -89,4 +95,8 @@ tasks { archiveVersion = destArchiveVersion archiveClassifier = destArchiveClassifier } + + compileJava { + dependsOn(common.tasks.getByName("remapForge")) + } } diff --git a/settings.gradle.kts b/settings.gradle.kts index d43c84fb..02f7d72c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -25,11 +25,9 @@ gradle.extra.apply { dependencyResolutionManagement { versionCatalogs { create("libs") { - library("minecraft", "com.mojang:minecraft:${gradle.extra.get("minecraft_version")}") library("fabric-loader", "net.fabricmc:fabric-loader:${gradle.extra.get("fabric_loader_version")}") library("forge", "net.minecraftforge:forge:${gradle.extra.get("minecraft_version")}-${gradle.extra.get("forge_loader_version")}") library("fabric-api", "net.fabricmc.fabric-api:fabric-api:${gradle.extra.get("fabric_api_version")}") - library("parchment", "org.parchmentmc.data:parchment-${gradle.extra.get("minecraft_version")}:${gradle.extra.get("parchment_version")}") library("worldmap-fabric", "maven.modrinth:xaeros-world-map:${gradle.extra.get("worldmap_version_fabric")}_Fabric_1.20") library("worldmap-forge", "maven.modrinth:xaeros-world-map:${gradle.extra.get("worldmap_version_forge")}_Forge_1.20") library("minimap-fabric", "maven.modrinth:xaeros-minimap:${gradle.extra.get("minimap_version_fabric")}_Fabric_1.20")