mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-20 14:16:26 -04:00
Speed up the Gradle build
- Exclude assets/data (~250MB) from sources jars - Limit licenser to .kt/.java so it doesn't scan ~29k resource files - Enable the Gradle daemon and build cache - The versioning plugin runs a full JGit status (~28s on this repo) in every project replace by ou own helper that use git local or CI env variable
This commit is contained in:
+5
-2
@@ -1,3 +1,6 @@
|
||||
import utilities.gitBranch
|
||||
import utilities.gitShortCommit
|
||||
|
||||
plugins {
|
||||
id("cobblemon.root-conventions")
|
||||
}
|
||||
@@ -6,6 +9,6 @@ version = "${project.property("mod_version")}+${project.property("mc_version")}"
|
||||
|
||||
val isSnapshot = project.property("snapshot")?.equals("true") == true
|
||||
if (isSnapshot) {
|
||||
val fixedBranchName = versioning.info.branch.substringAfter("/")
|
||||
version = "$version-${fixedBranchName}-${versioning.info.build}"
|
||||
val fixedBranchName = gitBranch().substringAfter("/")
|
||||
version = "$version-${fixedBranchName}-${gitShortCommit()}"
|
||||
}
|
||||
|
||||
+15
-6
@@ -1,9 +1,8 @@
|
||||
|
||||
import utilities.isSnapshot
|
||||
import utilities.version
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.ZoneOffset
|
||||
import java.time.format.DateTimeFormatter
|
||||
import utilities.gitBranch
|
||||
import utilities.gitCommit
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -72,6 +71,14 @@ tasks.withType<Test> {
|
||||
}
|
||||
}
|
||||
|
||||
// Git info lives in its own output dir (not processResources) so a new commit only rewrites this one file.
|
||||
val writeGitInfo by tasks.registering(WriteProperties::class) {
|
||||
destinationFile = layout.buildDirectory.file("generated/gitInfo/cobblemon-git.properties")
|
||||
property("commit", gitCommit())
|
||||
property("branch", gitBranch())
|
||||
}
|
||||
sourceSets.main { output.dir(mapOf("builtBy" to writeGitInfo), layout.buildDirectory.dir("generated/gitInfo")) }
|
||||
|
||||
tasks.processResources {
|
||||
exclude("data/**/README.md")
|
||||
}
|
||||
@@ -98,11 +105,13 @@ sourceSets {
|
||||
property("modid", "cobblemon")
|
||||
property("version", project.version())
|
||||
property("isSnapshot", if(rootProject.isSnapshot()) "true" else "false")
|
||||
property("gitCommit", versioning.info.commit)
|
||||
property("branch", versioning.info.branch)
|
||||
System.getProperty("buildNumber")?.let { property("buildNumber", it) }
|
||||
property("timestamp", OffsetDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss")) + " UTC")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The platform jars are built from :common:jar, so the remapped common jars are only needed by `publish`
|
||||
tasks.assemble {
|
||||
setDependsOn(dependsOn.filterNot { (it as? TaskProvider<*>)?.name in setOf("remapJar", "remapSourcesJar") })
|
||||
}
|
||||
|
||||
@@ -8,8 +8,12 @@ object CobblemonBuildDetails {
|
||||
const val VERSION = "{{ version }}"
|
||||
const val SNAPSHOT = {{ isSnapshot }}
|
||||
|
||||
const val GIT_COMMIT = "{{ gitCommit | default("Not Specified") }}"
|
||||
const val BRANCH = "{{ branch | default("Not Specified") }}"
|
||||
// Read at runtime rather than templated in, so a new commit doesn't invalidate compiled code.
|
||||
private val git = java.util.Properties().apply {
|
||||
CobblemonBuildDetails::class.java.getResourceAsStream("/cobblemon-git.properties")?.use(::load)
|
||||
}
|
||||
@JvmField val GIT_COMMIT: String = git.getProperty("commit", "Not Specified")
|
||||
@JvmField val BRANCH: String = git.getProperty("branch", "Not Specified")
|
||||
|
||||
fun smallCommitHash(): String {
|
||||
return this.GIT_COMMIT.substring(0, 7)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
||||
org.gradle.jvmargs=-Xmx8G
|
||||
org.gradle.daemon=false
|
||||
org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
group=com.cobblemon.mod
|
||||
|
||||
@@ -20,5 +20,4 @@ dependencies {
|
||||
|
||||
implementation(libs.blossom)
|
||||
implementation(libs.ideaExt)
|
||||
implementation(libs.versioning)
|
||||
}
|
||||
@@ -41,6 +41,7 @@ repositories {
|
||||
|
||||
license {
|
||||
header(rootProject.file("HEADER"))
|
||||
include("**/*.kt", "**/*.java")
|
||||
}
|
||||
|
||||
architectury {
|
||||
@@ -75,4 +76,16 @@ tasks {
|
||||
withType<Jar> {
|
||||
from(rootProject.file("LICENSE"))
|
||||
}
|
||||
|
||||
// Dev/intermediate jars only feed remapJar, which writes the compressed release jar.
|
||||
// Deflating ~250MB of already-compressed assets at every stage is wasted time.
|
||||
named<Jar>("jar") {
|
||||
entryCompression = ZipEntryCompression.STORED
|
||||
}
|
||||
|
||||
// Assets/data are ~250MB and already ship in the main jar; copying and remapping them
|
||||
// into sources jars cost minutes per build.
|
||||
withType<Jar>().named { it == "sourcesJar" }.configureEach {
|
||||
exclude("assets/**", "data/**")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ tasks {
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set("dev-shadow")
|
||||
entryCompression = ZipEntryCompression.STORED
|
||||
archiveBaseName.set("Cobblemon-${project.name}")
|
||||
configurations = listOf(bundle)
|
||||
mergeServiceFiles()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import utilities.VersionType
|
||||
import utilities.isSnapshot
|
||||
import utilities.gitCommit
|
||||
import utilities.writeVersion
|
||||
|
||||
plugins {
|
||||
@@ -7,7 +8,6 @@ plugins {
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("dev.architectury.loom")
|
||||
id("net.nemerosa.versioning")
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -53,7 +53,7 @@ publishing {
|
||||
version = project.writeVersion(VersionType.PUBLISHING)
|
||||
pom {
|
||||
properties = mapOf(
|
||||
"gitCommit" to versioning.info.commit
|
||||
"gitCommit" to project.gitCommit()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
base
|
||||
id("net.nemerosa.versioning")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -21,4 +21,16 @@ fun Project.writeVersion(type: VersionType = VersionType.FULL): String {
|
||||
enum class VersionType {
|
||||
PUBLISHING,
|
||||
FULL
|
||||
}
|
||||
}
|
||||
// Null when git isn't installed or this isn't a git checkout (e.g. a source zip download)
|
||||
private fun Project.git(vararg args: String): String? = runCatching {
|
||||
providers.exec {
|
||||
commandLine("git", *args)
|
||||
isIgnoreExitValue = true
|
||||
}.standardOutput.asText.get().trim()
|
||||
}.getOrNull()?.takeIf { it.isNotEmpty() }
|
||||
|
||||
// git CLI rather than the versioning plugin, whose JGit status scan costs ~30s per Gradle run. CI provides these.
|
||||
fun Project.gitCommit(): String = System.getenv("CI_COMMIT_SHA") ?: git("rev-parse", "HEAD") ?: "unknown"
|
||||
fun Project.gitShortCommit(): String = gitCommit().take(7)
|
||||
fun Project.gitBranch(): String = System.getenv("CI_COMMIT_REF_NAME") ?: git("rev-parse", "--abbrev-ref", "HEAD") ?: "unknown"
|
||||
|
||||
@@ -7,7 +7,6 @@ licenser = "0.6.1"
|
||||
shadow = "8.1.1"
|
||||
blossom = "2.1.0"
|
||||
idea-ext = "1.1.7"
|
||||
versioning = "3.1.0"
|
||||
|
||||
# Minecraft Development
|
||||
loom = "1.11-SNAPSHOT"
|
||||
@@ -59,7 +58,6 @@ shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "s
|
||||
blossom = { group = "net.kyori", name = "blossom", version.ref = "blossom" }
|
||||
ideaExt = { group = "org.jetbrains.gradle.plugin.idea-ext", name = "org.jetbrains.gradle.plugin.idea-ext.gradle.plugin", version.ref = "idea-ext"}
|
||||
licenser = { group = "gradle.plugin.org.cadixdev.gradle", name = "licenser", version.ref = "licenser" }
|
||||
versioning = { group = "net.nemerosa.versioning", name = "net.nemerosa.versioning.gradle.plugin", version.ref = "versioning" }
|
||||
|
||||
# Kotlin
|
||||
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }
|
||||
|
||||
Reference in New Issue
Block a user