From 609eb76ba0a2062e68257b74e7c2cba24371bf96 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Fri, 21 Jun 2024 19:55:10 +0100 Subject: [PATCH] Add build version option to prefix git hash with custom version property (#7222) * Add build version option to prefix git hash with custom version property * Refactor to make appending the git hash a boolean property. Include a commented-out example of how to use the properties in the gradle file Signed-off-by: Matthew Whitehead --- build.gradle | 4 ++++ gradle.properties | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/build.gradle b/build.gradle index b26f36b5194..3db0da35ce2 100644 --- a/build.gradle +++ b/build.gradle @@ -934,6 +934,10 @@ def calculateVersion() { def calVerPattern = ~/\d+\.\d+(\.\d+)?(-.*)?/ if (project.hasProperty('version') && (project.version =~ calVerPattern)) { + if (project.hasProperty('versionappendcommit') && project.versionappendcommit == "true") { + def gitDetails = getGitCommitDetails(7) // Adjust length as needed + return "${project.version}-${gitDetails.hash}" + } return "${project.version}" } else { // If no version is supplied or it doesn't match the semantic versioning, calculate from git diff --git a/gradle.properties b/gradle.properties index 61b69b61768..93f56e01379 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,9 @@ org.gradle.welcome=never + +# Optional - set custom build version +# version=24.5.6-acme +# versionappendcommit=true + # Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396) org.gradle.jvmargs=-Xmx4g \ --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \