Skip to content

Commit

Permalink
Add build version option to prefix git hash with custom version prope…
Browse files Browse the repository at this point in the history
…rty (#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 <[email protected]>
  • Loading branch information
matthew1001 authored Jun 21, 2024
1 parent 8c04d0a commit 609eb76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down

0 comments on commit 609eb76

Please sign in to comment.