File tree 1 file changed +15
-2
lines changed
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> =
96
96
isIgnoreExitValue = true
97
97
}.standardOutput.asText.map { it.trim() }
98
98
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
+
99
110
/* * Match simple SemVer tags. The first group is the `major.minor.patch` digits. */
100
111
val semverRegex = Regex (""" v((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))""" )
101
112
@@ -110,11 +121,13 @@ val gitVersion: Provider<String> =
110
121
val head = descriptions.singleOrNull() ? : " "
111
122
// drop the leading `v`, try to find the `major.minor.patch` digits group
112
123
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
114
127
}
115
128
}
116
129
117
130
gradle.allprojects {
118
- extensions.add<Provider <String >>(" gitVersion" , gitVersion)
131
+ extensions.add<Provider <String >>(" gitVersion" , standardVersion.orElse( gitVersion) )
119
132
}
120
133
// endregion
You can’t perform that action at this time.
0 commit comments