Skip to content

Commit

Permalink
Refactor to make appending the git hash a boolean property. Include a…
Browse files Browse the repository at this point in the history
… commented-out example of how to use the properties in the gradle file

Signed-off-by: Matthew Whitehead <[email protected]>
  • Loading branch information
matthew1001 committed Jun 17, 2024
1 parent 16ff080 commit 1e5dc4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,11 @@ 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 (project.hasProperty('versionprefix') && (project.versionprefix =~ calVerPattern)) {
def gitDetails = getGitCommitDetails(7) // Adjust length as needed
return "${project.versionprefix}-${gitDetails.hash}"
} else {
// If no version is supplied or it doesn't match the semantic versioning, calculate from git
println("Generating project version as supplied is version not semver: ${project.version}")
Expand Down
7 changes: 6 additions & 1 deletion 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 All @@ -13,4 +18,4 @@ org.gradle.jvmargs=-Xmx4g \
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
# Could be moved to sonar properties after https://sonarsource.atlassian.net/browse/SONARGRADL-134
systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.gradle.skipCompile=true

0 comments on commit 1e5dc4f

Please sign in to comment.