-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle.kts
95 lines (75 loc) · 2.19 KB
/
build.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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
plugins {
kotlin("jvm") version "1.3.61"
id("org.jetbrains.kotlin.plugin.serialization") version "1.3.60"
}
group = "mcajben.dungeonboard"
version = "dev"
val releaseVersion = "3.0.2"
val resourcesDir = File(buildDir, "resources/main")
val jarDir = File(buildDir, "libs")
val jarFile: File
get() = File(jarDir, "${rootProject.name}-$version.jar")
val releaseFile: File
get() = File("${rootProject.name}.v$releaseVersion.jar")
val readMeFile = File("README.md")
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
}
val jar = tasks.named<Jar>("jar") {
manifest {
attributes("Main-Class" to "main.MainKt")
}
from(configurations.compileClasspath.map { config ->
config.map { f ->
if (f.isDirectory) f
else zipTree(f)
}
})
}
val setReleaseVersion by tasks.registering {
version = releaseVersion
}
val generateVersionProperties by tasks.registering {
doLast {
val propertiesFile = File(resourcesDir, "version.properties")
propertiesFile.parentFile.mkdirs()
Properties().apply {
setProperty("version", version.toString())
store(propertiesFile.bufferedWriter(), null)
println(this)
}
}
}
tasks.named("processResources") {
dependsOn(generateVersionProperties)
}
val buildRelease by tasks.registering {
dependsOn(setReleaseVersion)
dependsOn(generateVersionProperties)
dependsOn(jar)
doLast {
releaseFile.delete()
jarFile.copyTo(releaseFile)
jarFile.delete()
readMeFile.writeText(
readMeFile.readText().replace(
Regex("""\[Download v.*]\(https://github.com/McAJBen/DungeonBoard/releases/download/v.*/DungeonBoard\.v.*\.jar\)"""),
"[Download v$releaseVersion](https://github.com/McAJBen/DungeonBoard/releases/download/v$releaseVersion/DungeonBoard.v$releaseVersion.jar)"
).replace(
Regex("""java -jar -Xmx2000m DungeonBoard\.v.*\.jar"""),
"java -jar -Xmx2000m DungeonBoard.v$releaseVersion.jar"
)
)
}
}