Skip to content

Commit

Permalink
Support Gradle configuration cache, small buildscript cleanups (#107)
Browse files Browse the repository at this point in the history
* Bump Gradle to 8.12, rework buildscript to use Gradle configuration cache

Signed-off-by: xtrm <[email protected]>

* Use Foojay Resolver for toolchains, pin `rootProject.name` for concistency

Signed-off-by: xtrm <[email protected]>

* Move repository declaration in settings.gradle.kts

Signed-off-by: xtrm <[email protected]>

* Apply requested changes

Signed-off-by: xtrm <[email protected]>

---------

Signed-off-by: xtrm <[email protected]>
  • Loading branch information
xtrm-en authored Dec 24, 2024
1 parent 8f97cf9 commit e98e90d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 117 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ run/
client.txt

libs/
src/forge
src/forge
kotlin-compiler-*.salive
157 changes: 46 additions & 111 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:Suppress("LocalVariableName", "UnstableApiUsage")

import org.ajoberstar.grgit.Grgit
import org.jetbrains.kotlin.daemon.common.toHexString
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import xyz.bluspring.kilt.gradle.AccessTransformerRemapper
import java.security.MessageDigest

Expand Down Expand Up @@ -37,77 +40,6 @@ loom {
}
}

repositories {
mavenCentral()
mavenLocal()

maven("https://mvn.devos.one/releases/") {
name = "devOS Maven"
}

maven("https://mvn.devos.one/snapshots/") {
name = "devOS Maven (Snapshots)"
}

maven("https://jitpack.io/") {
name = "JitPack"
}

maven("https://maven.cafeteria.dev/releases/") {
name = "Cafeteria Dev"
}

maven("https://maven.jamieswhiteshirt.com/libs-release") {
name = "JamiesWhiteShirt Dev"
content {
includeGroup("com.jamieswhiteshirt")
}
}

maven("https://raw.githubusercontent.com/Fuzss/modresources/main/maven/") {
name = "Fuzs Mod Resources"
}

maven("https://maven.minecraftforge.net/") {
name = "MinecraftForge Maven"
}

maven("https://maven.architectury.dev") {
name = "Architectury"
}

maven("https://maven.parchmentmc.org") {
name = "ParchmentMC"
}

flatDir {
dir("libs")
}

// Testing mod sources
maven("https://api.modrinth.com/maven") {
name = "Modrinth"
content {
includeGroup("maven.modrinth")
}
}

maven("https://cursemaven.com") {
name = "CurseMaven"
content {
includeGroup("curse.maven")
}
}

maven("https://maven.terraformersmc.com/") {
name = "TerraformersMC"
}

maven("https://maven.su5ed.dev/releases") {
name = "Su5ed"
}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft ("com.mojang:minecraft:${property("minecraft_version")}")
Expand Down Expand Up @@ -229,16 +161,20 @@ java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

interface InjectedServices {
@get:Inject val fs: FileSystemOperations
@get:Inject val layout: ProjectLayout
@get:Inject val provider: ProviderFactory
}

tasks {
register("countPatchProgress") {
group = "kilt"
description = "Counts the total of patches in Forge, and checks how many Kilt ForgeInjects there are, to check how much is remaining."
notCompatibleWithConfigurationCache("Must not be cached")

doFirst {
// Scan Forge patches dir
Expand Down Expand Up @@ -271,6 +207,7 @@ tasks {
register("tagPatches") {
group = "kilt"
description = "Tags the Kilt ForgeInjects with their currently tracked patch hash to ensure they are all up to date."
notCompatibleWithConfigurationCache("Must not be cached")

doFirst {
fun readDir(file: File) {
Expand Down Expand Up @@ -314,28 +251,26 @@ tasks {
}
}

val projectVersion = project.version

processResources {
inputs.property("version", project.version)
inputs.property("loader_version", project.property("loader_version"))
inputs.property("fabric_version", project.property("fabric_version"))
inputs.property("minecraft_version", project.property("minecraft_version"))
inputs.property("fabric_kotlin_version", project.property("fabric_kotlin_version"))
inputs.property("fabric_asm_version", project.property("fabric_asm_version"))
inputs.property("forge_config_version", project.property("forgeconfigapiport_version"))
inputs.property("architectury_version", project.property("architectury_version"))
val provider = objects.newInstance<InjectedServices>().provider
val propertiesMap = mutableMapOf(
"version" to projectVersion,
"loader_version" to provider.gradleProperty("loader_version"),
"fabric_version" to provider.gradleProperty("fabric_version"),
"minecraft_version" to provider.gradleProperty("minecraft_version"),
"fabric_kotlin_version" to provider.gradleProperty("fabric_kotlin_version"),
"fabric_asm_version" to provider.gradleProperty("fabric_asm_version"),
"forge_config_version" to provider.gradleProperty("forgeconfigapiport_version"),
"architectury_version" to provider.gradleProperty("architectury_version"),
)
propertiesMap.forEach { (key, value) -> inputs.property(key, value) }

filteringCharset = "UTF-8"

filesMatching("fabric.mod.json") {
expand(mutableMapOf(
"version" to project.version,
"loader_version" to project.property("loader_version"),
"fabric_version" to project.property("fabric_version"),
"minecraft_version" to project.property("minecraft_version"),
"fabric_kotlin_version" to project.property("fabric_kotlin_version"),
"fabric_asm_version" to project.property("fabric_asm_version"),
"forge_config_version" to project.property("forgeconfigapiport_version"),
"architectury_version" to project.property("architectury_version"),
))
expand(propertiesMap)
}

// Rename Forge's mods.toml, so launchers like Prism don't end up detecting it over Kilt.
Expand All @@ -345,7 +280,9 @@ tasks {
}

compileKotlin {
kotlinOptions.jvmTarget = targetJavaVersion
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion))
}
}

jar {
Expand All @@ -371,35 +308,33 @@ tasks {
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
mavenLocal()
}
}

register("setupDevEnvironment") {
group = "kilt"

val services = project.objects.newInstance<InjectedServices>()
doLast {
val configDir = File("$projectDir/run/config")
if (!configDir.exists())
configDir.mkdirs()

val loaderDepsFile = File(configDir, "fabric_loader_dependencies.json")

if (!loaderDepsFile.exists())
loaderDepsFile.createNewFile()

loaderDepsFile.writeText(File("$projectDir/gradle/loader_dep_overrides.json").readText())
val configDir = services.layout.projectDirectory.dir("run/config")
configDir.asFile.mkdirs()

val loaderDepsFile = configDir.file("fabric_loader_dependencies.json")
val templateFile = services.layout.projectDirectory.file("gradle/loader_dep_overrides.json")
services.fs.copy {
from(templateFile)
into(loaderDepsFile)
}
}
}

register("transformerToWidener") {
group = "kilt"
notCompatibleWithConfigurationCache("Must not be cached")

val minecraft_version: String by project
doLast {
val remapper = AccessTransformerRemapper()
val transformerFile = File("$projectDir/forge/src/main/resources/META-INF/accesstransformer.cfg")
Expand All @@ -408,8 +343,8 @@ tasks {
remapper.convertTransformerToWidener(
transformerFile.readText(),
widenerFile,
project.property("minecraft_version") as String,
layout.buildDirectory.get().asFile
minecraft_version,
layout.buildDirectory.asFile.get()
)
}
}
Expand All @@ -423,4 +358,4 @@ fun getVersionMetadata(): String {
System.getenv("GITHUB_SHA") ?: grgit.head().abbreviatedId

return "+build.${commitHash.subSequence(0, 6)}${if (System.getenv("GITHUB_RUN_NUMBER") == null) "-local" else ""}"
}
}
15 changes: 11 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
Expand Down Expand Up @@ -82,4 +79,14 @@ forgerenamer_version=0.1.48
securejarhandler_version=fabric-2.1.6

# https://mvnrepository.com/artifact/org.openjdk.nashorn/nashorn-core
nashorn_version=15.4
nashorn_version=15.4


# Gradle configuration
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.parallel.threads=4
org.gradle.configureondemand=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
org.gradle.jvmargs=-Xmx2G -Dfile.encoding=UTF-8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
84 changes: 84 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
@file:Suppress("UnstableApiUsage")

import org.gradle.kotlin.dsl.dir
import org.gradle.kotlin.dsl.flatDir
import org.gradle.kotlin.dsl.mavenCentral


enableFeaturePreview("STABLE_CONFIGURATION_CACHE")

pluginManagement {
repositories {
maven("https://maven.fabricmc.net/") {
Expand All @@ -16,3 +25,78 @@ pluginManagement {
.split("+")[0] // Ensures sentences like `+build.1` are ignored
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
mavenLocal()

maven("https://mvn.devos.one/releases/") {
name = "devOS Maven"
}

maven("https://mvn.devos.one/snapshots/") {
name = "devOS Maven (Snapshots)"
}

maven("https://jitpack.io/") {
name = "JitPack"
}

maven("https://maven.cafeteria.dev/releases/") {
name = "Cafeteria Dev"
}

maven("https://maven.jamieswhiteshirt.com/libs-release") {
name = "JamiesWhiteShirt Dev"
content {
includeGroup("com.jamieswhiteshirt")
}
}

maven("https://raw.githubusercontent.com/Fuzss/modresources/main/maven/") {
name = "Fuzs Mod Resources"
}

maven("https://maven.minecraftforge.net/") {
name = "MinecraftForge Maven"
}

maven("https://maven.architectury.dev") {
name = "Architectury"
}

maven("https://maven.parchmentmc.org") {
name = "ParchmentMC"
}

flatDir {
dir("libs")
}

// Testing mod sources
maven("https://api.modrinth.com/maven") {
name = "Modrinth"
content {
includeGroup("maven.modrinth")
}
}

maven("https://cursemaven.com") {
name = "CurseMaven"
content {
includeGroup("curse.maven")
}
}

maven("https://maven.terraformersmc.com/") {
name = "TerraformersMC"
}

maven("https://maven.su5ed.dev/releases") {
name = "Su5ed"
}
}
}

rootProject.name = "Kilt"

0 comments on commit e98e90d

Please sign in to comment.