From 0b126f77e28bfb774fc071897d70e4628da63434 Mon Sep 17 00:00:00 2001 From: Su5eD Date: Sun, 16 Jun 2024 10:58:39 +0200 Subject: [PATCH] Move from grgit to jgit --- build.gradle.kts | 11 ++++++----- buildSrc/build.gradle.kts | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa8550ecd..c5eca5bb8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,12 +3,12 @@ import net.fabricmc.loom.build.nesting.JarNester import net.fabricmc.loom.util.Constants import net.fabricmc.loom.util.GroovyXmlUtil import org.apache.commons.codec.digest.DigestUtils +import org.eclipse.jgit.api.Git import java.util.* plugins { java `maven-publish` - id("org.ajoberstar.grgit") version "4.1.1" id("dev.architectury.loom") // Version declared in buildSrc } @@ -213,22 +213,23 @@ publishing { } } +val git: Git? = runCatching { Git.open(rootDir) }.getOrNull() + fun getSubprojectVersion(project: Project): String { // Get the version from the gradle.properties file val version = properties["${project.name}-version"] as? String ?: throw NullPointerException("Could not find version for " + project.name) - @Suppress("SENSELESS_COMPARISON") - if (rootProject.grgit == null) { + if (git == null) { return "$version+nogit" } - val latestCommits = rootProject.grgit.log(mapOf("paths" to listOf(project.name), "maxCommits" to 1)) + val latestCommits = git.log().addPath(project.name).setMaxCount(1).call().toList() if (latestCommits.isEmpty()) { return "$version+uncommited" } - return version + "+" + latestCommits[0].id.substring(0, 8) + DigestUtils.sha256Hex(versionMc).substring(0, 2) + return version + "+" + latestCommits[0].id.name.substring(0, 8) + DigestUtils.sha256Hex(versionMc).substring(0, 2) } fun moduleDependencies(project: Project, depNames: List) { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 2dc24de0b..d3e418384 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -37,4 +37,6 @@ dependencies { implementation("dev.architectury:at:1.0.1") implementation("commons-codec:commons-codec:1.17.0") + + implementation("org.eclipse.jgit:org.eclipse.jgit:6.9.0.202403050737-r") } \ No newline at end of file