-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.gradle.kts
127 lines (96 loc) · 3.61 KB
/
versioning.gradle.kts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.Properties
class ApplicationVersion(
private val major: Int,
private val minor: Int,
private val patch: Int,
private val release: Boolean
) {
private fun getRelease(): String {
return if (release) "" else "-SNAPSHOT"
}
fun getVersion(): String {
return "$major.$minor.$patch" + getRelease()
}
}
val loadVersion: () -> String = {
val versionPropertiesFile = File("src/main/resources/version.properties")
if (!versionPropertiesFile.exists()) {
throw Exception("No version.properties file found")
}
val versionProperties = Properties()
versionPropertiesFile.inputStream().use { stream ->
versionProperties.load(stream)
}
val major = versionProperties.getProperty("major")?.toInt() ?: 0
val minor = versionProperties.getProperty("minor")?.toInt() ?: 0
val patch = versionProperties.getProperty("patch")?.toInt() ?: 0
val release = versionProperties.getProperty("release")?.toBoolean() ?: false
val version = ApplicationVersion(major, minor, patch, release)
version.getVersion()
}
version = loadVersion()
tasks.withType<Jar> {
manifest {
attributes["Implementation-Version"] = version
}
}
tasks.register("majorVersionUpdate") {
group = "versioning"
description = "Bump to next major version"
doFirst {
val versionFile = File("src/main/resources/version.properties")
val properties = Properties()
versionFile.inputStream().use { stream ->
properties.load(stream)
}
properties.setProperty("major", (properties.getProperty("major").toInt() + 1).toString())
properties.setProperty("minor", "0")
properties.setProperty("patch", "0")
versionFile.outputStream().use { properties.store(it, null) }
}
}
tasks.register("minorVersionUpdate") {
group = "versioning"
description = "Bump to next minor version"
doFirst {
val versionFile = file("src/main/resources/version.properties")
val properties = Properties()
versionFile.inputStream().use { properties.load(it) }
properties.setProperty("minor", (properties.getProperty("minor").toInt() + 1).toString())
properties.setProperty("patch", "0")
versionFile.outputStream().use { properties.store(it, null) }
}
}
tasks.register("patchVersionUpdate") {
group = "versioning"
description = "Bump to next patch version"
doFirst {
val versionFile = file("src/main/resources/version.properties")
val properties = Properties()
versionFile.inputStream().use { properties.load(it) }
properties.setProperty("patch", (properties.getProperty("patch").toInt() + 1).toString())
versionFile.outputStream().use { properties.store(it, null) }
}
}
tasks.register("releaseVersion") {
group = "versioning"
description = "Make the version a release"
doFirst {
val versionFile = file("src/main/resources/version.properties")
val properties = Properties()
versionFile.inputStream().use { properties.load(it) }
properties.setProperty("release", "true")
versionFile.outputStream().use { properties.store(it, null) }
}
}
tasks.register("preReleaseVersion") {
group = "versioning"
description = "Make the version a pre release"
doFirst {
val versionFile = file("src/main/resources/version.properties")
val properties = Properties()
versionFile.inputStream().use { properties.load(it) }
properties.setProperty("release", "false")
versionFile.outputStream().use { properties.store(it, null) }
}
}