Skip to content

Commit

Permalink
move common gradle project configuration to conventions plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Oct 7, 2024
1 parent 52711f8 commit becad4e
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 108 deletions.
122 changes: 21 additions & 101 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<LoomGradleExtensionAPI> {
silentMojangMappingsLicense()
runs {
getByName("client") {
programArgs("--username", "rfresh2")
}
}
}

dependencies {
"minecraft"(mc)
"mappings"((project.extensions.getByType(LoomGradleExtensionAPI::class)).layered {
officialMojangMappings()
parchment(parchment)
})
}

tasks {
getByName<ShadowJar>("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<BasePluginExtension> {
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<JavaCompile> {
options.encoding = "UTF-8"
options.release = 17
}
}

configure<JavaPluginExtension> {
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 }
}
}

Expand Down
18 changes: 18 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}

42 changes: 42 additions & 0 deletions buildSrc/src/main/kotlin/xaeroplus-all.conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
java
id("maven-publish")
id("architectury-plugin")
}

configure<BasePluginExtension> {
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<JavaCompile> {
options.encoding = "UTF-8"
options.release = 17
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
49 changes: 49 additions & 0 deletions buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -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/**")
}
}
16 changes: 11 additions & 5 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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(","))
}
Expand All @@ -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
Expand Down Expand Up @@ -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) ->
Expand All @@ -73,6 +80,5 @@ tasks {
}
}
}
compileJava.get().dependsOn(remapForgeTask)
}

5 changes: 5 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id("xaeroplus-all.conventions")
id("xaeroplus-platform.conventions")
}

architectury {
platformSetupLoomIde()
fabric()
Expand Down
10 changes: 10 additions & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -57,6 +62,7 @@ dependencies {

tasks {
processResources {
dependsOn(common.tasks.getByName("remapForge"))
filesMatching("META-INF/mods.toml") {
expand(mapOf(
"version" to project.version,
Expand Down Expand Up @@ -89,4 +95,8 @@ tasks {
archiveVersion = destArchiveVersion
archiveClassifier = destArchiveClassifier
}

compileJava {
dependsOn(common.tasks.getByName("remapForge"))
}
}
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit becad4e

Please sign in to comment.