-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
146 lines (125 loc) · 4.5 KB
/
build.gradle.kts
File metadata and controls
146 lines (125 loc) · 4.5 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import net.minecrell.pluginyml.paper.PaperPluginDescription
import java.util.*
import java.text.SimpleDateFormat
plugins {
id("java")
id("maven-publish")
id("net.kyori.blossom") version "2.2.0"
id("com.gradleup.shadow") version ("9.3.1")
id("de.eldoria.plugin-yml.paper") version ("0.8.0")
}
group = "eu.koolfreedom"
version = "2.0"
description = "KoolChatFilter"
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.codemc.io/repository/maven-releases/")
maven("https://repo.codemc.io/repository/maven-snapshots/")
}
paper {
name = rootProject.name.toString()
version = project.version.toString()
description = "Random chat filter plugin"
main = "eu.koolfreedom.KoolChatFilter"
loader = "eu.koolfreedom.KoolLibraryManager"
website = "https://github.com/KoolFreedom"
authors = listOf("gamingto12")
apiVersion = "1.21"
generateLibrariesJson = true
}
dependencies {
// Paper API
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
// Utilities
implementation("org.apache.commons:commons-lang3:3.18.0")
implementation("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
implementation("org.reflections:reflections:0.10.2")
// Misc
implementation("com.google.code.gson:gson:2.10.1")
}
tasks {
// Update build.properties with build information
processResources {
val buildAuthor = project.findProperty("buildAuthor") ?: "KoolFreedom"
val buildNumber = getBuildNumber()
val buildDate = SimpleDateFormat("M/dd/yyyy 'at' h:mm:ss aa zzz").format(Date())
inputs.property("buildAuthor", buildAuthor)
inputs.property("buildNumber", buildNumber)
inputs.property("buildVersion", project.version)
inputs.property("buildDate", buildDate)
filesMatching("build.properties") {
expand(mapOf(
"buildAuthor" to buildAuthor,
"buildNumber" to buildNumber,
"buildVersion" to project.version,
"buildDate" to buildDate
))
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
shadowJar {
archiveFileName.set("KoolChatFilter-${project.version}.jar")
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
exclude("META-INF/versions/**")
mergeServiceFiles()
relocate("com.google.gson", "eu.koolfreedom.libs.gson")
}
build {
dependsOn(shadowJar)
}
}
/**
* Read the current build number from build.properties and increment it.
* If the file doesn't exist or the property isn't found, returns 1.
*/
fun getBuildNumber(): Int {
val buildPropsFile = file("src/main/resources/build.properties")
if (!buildPropsFile.exists()) {
return 1
}
val props = mutableMapOf<String, String>()
buildPropsFile.readLines().forEach { line ->
if (line.isNotEmpty() && !line.startsWith("#")) {
val (key, value) = line.split("=", limit = 2).let { parts ->
if (parts.size == 2) parts[0] to parts[1] else return@forEach
}
props[key.trim()] = value.trim()
}
}
val currentNumber = (props["buildNumber"] ?: "0").toIntOrNull() ?: 0
return currentNumber + 1
}
/**
* Task to increment build number in build.properties
*/
tasks.register("incrementBuildNumber") {
doLast {
val buildPropsFile = file("src/main/resources/build.properties")
buildPropsFile.parentFile.mkdirs()
val props = mutableMapOf<String, String>()
if (buildPropsFile.exists()) {
buildPropsFile.readLines().forEach { line ->
if (line.isNotEmpty() && !line.startsWith("#")) {
val (key, value) = line.split("=", limit = 2).let { parts ->
if (parts.size == 2) parts[0] to parts[1] else return@forEach
}
props[key.trim()] = value.trim()
}
}
}
val currentNumber = (props["buildNumber"] ?: "0").toIntOrNull() ?: 0
props["buildNumber"] = (currentNumber + 1).toString()
props["buildVersion"] = project.version.toString()
props["buildDate"] = System.currentTimeMillis().toString()
buildPropsFile.writeText(props.entries.joinToString("\n") { (k, v) -> "$k=$v" })
}
}