Skip to content

Commit

Permalink
wip try to enable configuration-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 5, 2024
1 parent 9e851b4 commit f898860
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 35 deletions.
12 changes: 12 additions & 0 deletions Common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ val minecraftVersion: String by extra
val neoformTimestamp: String by extra
val modId: String by extra
val modJavaVersion: String by extra
val modName: String by extra

val resourceProperties = mapOf("modName" to modName)

val baseArchivesName = "${modId}-${minecraftVersion}-common"
base {
Expand Down Expand Up @@ -88,6 +91,15 @@ tasks.withType<JavaCompile> {
}
}

tasks.withType<ProcessResources> {
// this will ensure that this task is redone when the versions change.
inputs.properties(resourceProperties)

filesMatching("pack.mcmeta") {
expand(resourceProperties)
}
}

publishing {
publications {
register<MavenPublication>("commonJar") {
Expand Down
11 changes: 11 additions & 0 deletions Fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ val modJavaVersion: String by extra
val parchmentVersionFabric: String by extra
val parchmentMinecraftVersion: String by extra

val resourceProperties: Map<String, String> by rootProject.extra

// set by ORG_GRADLE_PROJECT_modrinthToken in Jenkinsfile
val modrinthToken: String? by project

Expand Down Expand Up @@ -72,6 +74,15 @@ tasks.withType<JavaCompile> {
}
}

tasks.withType<ProcessResources> {
// this will ensure that this task is redone when the versions change.
inputs.properties(resourceProperties)

filesMatching( "fabric.mod.json") {
expand(resourceProperties)
}
}

dependencies {
minecraft(
group = "com.mojang",
Expand Down
17 changes: 16 additions & 1 deletion Forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import net.minecraftforge.gradle.common.tasks.DownloadMavenArtifact
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import net.darkhax.curseforgegradle.Constants as CFG_Constants
Expand All @@ -25,6 +26,8 @@ val modId: String by extra
val modJavaVersion: String by extra
val parchmentVersionForge: String by extra

val resourceProperties: Map<String, String> by rootProject.extra

// set by ORG_GRADLE_PROJECT_modrinthToken in Jenkinsfile
val modrinthToken: String? by project

Expand Down Expand Up @@ -148,10 +151,18 @@ tasks.withType<JavaCompile>().configureEach {
}
}

tasks.processResources {
tasks.withType<ProcessResources> {
dependencyProjects.forEach {
inputs.files(it.sourceSets.main.get().resources)
from(it.sourceSets.main.get().resources)
}

// this will ensure that this task is redone when the versions change.
inputs.properties(resourceProperties)

filesMatching("META-INF/mods.toml") {
expand(resourceProperties)
}
}

tasks.jar {
Expand Down Expand Up @@ -247,3 +258,7 @@ sourceSets.forEach {
it.output.setResourcesDir(outputDir)
it.java.destinationDirectory.set(outputDir)
}

tasks.withType<DownloadMavenArtifact> {
notCompatibleWithConfigurationCache("uses Task.project at execution time")
}
6 changes: 6 additions & 0 deletions ForgeApi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import net.minecraftforge.gradle.common.tasks.DownloadMavenArtifact

plugins {
id("java")
id("idea")
Expand Down Expand Up @@ -120,3 +122,7 @@ publishing {
}
}
}

tasks.withType<DownloadMavenArtifact> {
notCompatibleWithConfigurationCache("uses Task.project at execution time")
}
12 changes: 11 additions & 1 deletion NeoForge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ val modGroup: String by extra
val modId: String by extra
val modJavaVersion: String by extra

val resourceProperties: Map<String, String> by rootProject.extra

// set by ORG_GRADLE_PROJECT_modrinthToken in Jenkinsfile
val modrinthToken: String? by project

Expand Down Expand Up @@ -61,10 +63,18 @@ tasks.withType<JavaCompile>().configureEach {
}
}

tasks.withType<ProcessResources>().configureEach {
tasks.withType<ProcessResources> {
dependencyProjects.forEach {
inputs.files(it.sourceSets.main.get().resources)
from(it.sourceSets.main.get().resources)
}

// this will ensure that this task is redone when the properties change.
inputs.properties(resourceProperties)

filesMatching("META-INF/neoforge.mods.toml") {
expand(resourceProperties)
}
}

java {
Expand Down
60 changes: 27 additions & 33 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ val modJavaVersion: String by extra
val modName: String by extra
val specificationVersion: String by extra

//adds the build number to the end of the version string if on a build server
var buildNumber = project.findProperty("BUILD_NUMBER")
if (buildNumber == null) {
buildNumber = "9999"
}
val stringVersion = "${specificationVersion}.${buildNumber}"

val resourceProperties by extra(mapOf(
"curseHomepageUrl" to curseHomepageUrl,
"fabricApiVersion" to fabricApiVersion,
"fabricLoaderVersion" to fabricLoaderVersion,
"forgeVersionRange" to forgeVersionRange,
"githubUrl" to githubUrl,
"forgeLoaderVersionRange" to forgeLoaderVersionRange,
"neoforgeVersionRange" to neoforgeVersionRange,
"neoforgeLoaderVersionRange" to neoforgeLoaderVersionRange,
"minecraftVersion" to minecraftVersion,
"minecraftVersionRange" to minecraftVersionRange,
"modAuthor" to modAuthor,
"modDescription" to modDescription,
"modId" to modId,
"modJavaVersion" to modJavaVersion,
"modName" to modName,
"version" to stringVersion,
))

spotless {
java {
target("*/src/*/java/mezz/jei/**/*.java")
Expand All @@ -66,13 +92,7 @@ spotless {
}

subprojects {
//adds the build number to the end of the version string if on a build server
var buildNumber = project.findProperty("BUILD_NUMBER")
if (buildNumber == null) {
buildNumber = "9999"
}

version = "${specificationVersion}.${buildNumber}"
version = stringVersion
group = modGroup

tasks.withType<Javadoc> {
Expand Down Expand Up @@ -100,32 +120,6 @@ subprojects {
}
}

tasks.withType<ProcessResources> {
// this will ensure that this task is redone when the versions change.
inputs.property("version", version)

filesMatching(listOf("META-INF/mods.toml", "META-INF/neoforge.mods.toml", "pack.mcmeta", "fabric.mod.json")) {
expand(mapOf(
"curseHomepageUrl" to curseHomepageUrl,
"fabricApiVersion" to fabricApiVersion,
"fabricLoaderVersion" to fabricLoaderVersion,
"forgeVersionRange" to forgeVersionRange,
"githubUrl" to githubUrl,
"forgeLoaderVersionRange" to forgeLoaderVersionRange,
"neoforgeVersionRange" to neoforgeVersionRange,
"neoforgeLoaderVersionRange" to neoforgeLoaderVersionRange,
"minecraftVersion" to minecraftVersion,
"minecraftVersionRange" to minecraftVersionRange,
"modAuthor" to modAuthor,
"modDescription" to modDescription,
"modId" to modId,
"modJavaVersion" to modJavaVersion,
"modName" to modName,
"version" to version,
))
}
}

// Activate reproducible builds
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
tasks.withType<AbstractArchiveTask>().configureEach {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ org.gradle.daemon=true
# Disabled because this breaks ForgeGradle tasks
org.gradle.configureondemand=false
org.gradle.caching=true
org.gradle.configuration-cache=true

# JEI
modName=Just Enough Items
Expand Down

0 comments on commit f898860

Please sign in to comment.