-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.sbt
47 lines (36 loc) · 1.4 KB
/
version.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
val buildVersion = "1.0.0-SNAPSHOT"
// *******************************
// Semantic Versioning Update
// *******************************
val VersionRegex = """([0-9]+)(?:(?:\.([0-9]+))?(?:\.([0-9]+))?)?([\-0-9a-zA-Z]*)?""".r
// We need to remove whitespace here for 0.13.5 sbt, but 0.13.7 sbt includes them just fine
def setVersionFunc(versionStr: String): String = {
val VersionRegex(major, minor, defaultBld, defaultQual) = versionStr
val qualOverride = System.getProperty("packaging.buildQualifier")
val qual = if (qualOverride == null) {
defaultQual
} else {
qualOverride
}
// If this is string.Empty it should explode in a fiery battle.
val bldOverride = System.getProperty("packaging.buildNumber")
val bld = if (bldOverride == null) {
defaultBld
} else if (bldOverride.isEmpty()) {
throw new Exception("packaging.buildNumber has to be set if it is used")
} else {
bldOverride
}
s"$major.$minor.$bld$qual"
}
// Avoid weird cyclical dependencies in SBT
version := setVersionFunc(buildVersion)
version in ThisBuild := setVersionFunc(buildVersion)
// *******************************
// Output version to target
// *******************************
lazy val outputVersion = taskKey[Unit]("Outputs current version to version.txt in targets")
outputVersion in Compile := {
val file = baseDirectory.value / "target" / "version.txt"
IO.write(file, version in ThisBuild value)
}