File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,17 @@ val currentCommitHash: Provider<String> =
9696 isIgnoreExitValue = true
9797 }.standardOutput.asText.map { it.trim() }
9898
99+ /* *
100+ * The standard Gradle way of setting the version, which can be set on the CLI with
101+ *
102+ * ```shell
103+ * ./gradlew -Pversion=1.2.3
104+ * ```
105+ *
106+ * This can be used to override [gitVersion].
107+ */
108+ val standardVersion: Provider <String > = providers.gradleProperty(" version" )
109+
99110/* * Match simple SemVer tags. The first group is the `major.minor.patch` digits. */
100111val semverRegex = Regex (""" v((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))""" )
101112
@@ -110,11 +121,13 @@ val gitVersion: Provider<String> =
110121 val head = descriptions.singleOrNull() ? : " "
111122 // drop the leading `v`, try to find the `major.minor.patch` digits group
112123 val headVersion = semverRegex.matchEntire(head)?.groupValues?.last()
113- headVersion ? : currentCommitHash.get() // fall back to using the git commit hash
124+ headVersion
125+ ? : currentCommitHash.orNull // fall back to using the git commit hash
126+ ? : " unknown" // just in case there's no git repo, e.g. someone downloaded a zip archive
114127 }
115128 }
116129
117130gradle.allprojects {
118- extensions.add<Provider <String >>(" gitVersion" , gitVersion)
131+ extensions.add<Provider <String >>(" gitVersion" , standardVersion.orElse( gitVersion) )
119132}
120133// endregion
You can’t perform that action at this time.
0 commit comments