-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
74 lines (64 loc) · 2 KB
/
build.gradle.kts
File metadata and controls
74 lines (64 loc) · 2 KB
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
import org.jetbrains.kotlin.com.google.gson.Gson
import org.jetbrains.kotlin.com.google.gson.GsonBuilder
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
import java.time.Instant
plugins {
kotlin("jvm") version "1.7.20"
kotlin("plugin.serialization") version "1.7.20"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("java")
application
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
implementation("org.quartz-scheduler:quartz:2.3.2")
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
testImplementation("org.slf4j:slf4j-simple:2.0.6")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClass.set("MainKt")
}
/**
* Update the version / build-result file
*/
tasks.create("incrementVersion") {
group = "chronos"
doLast {
val gson = GsonBuilder().setPrettyPrinting().serializeNulls().create()
val fileName = "chronos.version.json"
val chronosFile = File(projectDir, fileName)
val creationTimestamp = Instant.now().epochSecond
var buildNumber = 0
// Read version file
chronosFile.exists().ifTrue {
val content = chronosFile.readText()
val kvs = gson.fromJson(content, HashMap::class.java)
buildNumber = (kvs["buildNumber"] as Double? ?: 0).toInt()
}
// Write version file
chronosFile.writeText(gson.toJson(mapOf<String, Any>(
"buildNumber" to buildNumber + 1,
"creationTimestamp" to creationTimestamp
)))
}
}
/**
* Execute "jar"-task after "incrementVersion"-task
*/
tasks.getByName("jar") {
dependsOn(tasks.getByName("incrementVersion"))
}