@@ -3,7 +3,30 @@ import java.io.ByteArrayOutputStream
33plugins {
44 id(" java" )
55 id(" com.gradleup.shadow" ) version " 8.3.3" apply false
6- id(" fabric-loom" ) version " 1.10.5" apply false
6+ id(" fabric-loom" ) version " 1.11.8" apply false
7+ }
8+
9+ fun getGitCommitHash (project : Project ): String? {
10+ // Only try to get the hash if the .git directory exists
11+ if (! project.file(" .git" ).isDirectory) {
12+ return null
13+ }
14+ return try {
15+ val process = ProcessBuilder (" git" , " rev-parse" , " --short" , " HEAD" )
16+ .redirectOutput(ProcessBuilder .Redirect .PIPE )
17+ .redirectError(ProcessBuilder .Redirect .PIPE )
18+ .start()
19+
20+ process.waitFor(5 , TimeUnit .SECONDS )
21+
22+ if (process.exitValue() == 0 ) {
23+ process.inputStream.bufferedReader().readText().trim().takeIf { it.isNotEmpty() }
24+ } else {
25+ null
26+ }
27+ } catch (e: Exception ) {
28+ null
29+ }
730}
831
932val fullVersion = " 1.3.5"
@@ -23,14 +46,10 @@ allprojects {
2346 if (! snapshot) {
2447 return " "
2548 }
26- var commitHash = " "
27- if (includeHash && file(" .git" ).isDirectory) {
28- val stdout = ByteArrayOutputStream ()
29- exec {
30- commandLine(" git" , " rev-parse" , " --short" , " HEAD" )
31- standardOutput = stdout
32- }
33- commitHash = " +${stdout.toString().trim()} "
49+ val commitHash = if (includeHash) {
50+ getGitCommitHash(project)?.let { " +$it " } ? : " "
51+ } else {
52+ " "
3453 }
3554 return " $commitHash -SNAPSHOT"
3655 }
0 commit comments