-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
243 lines (201 loc) · 6.96 KB
/
build.gradle.kts
File metadata and controls
243 lines (201 loc) · 6.96 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import com.google.gson.Gson
import org.ajoberstar.grgit.Commit
import org.ajoberstar.grgit.Grgit
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.net.URI
import java.net.URL
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.detekt)
// alias(libs.plugins.detekt.compiler)
alias(libs.plugins.grgit)
alias(libs.plugins.yamlang)
alias(libs.plugins.shadow)
}
base {
val grgit: Grgit? by lazy(LazyThreadSafetyMode.NONE) {
runCatching {
grgitService.service.get().grgit
}.getOrNull()
}
fun getLatestCommit(): Commit? = grgit?.head()
fun getLatestTagCommit(): Commit? = grgit!!.tag.list().orEmpty().lastOrNull()?.commit
fun getUnreleasedCommits(): Int = if (getLatestTagCommit() != null) {
grgit!!.log {
range(getLatestTagCommit(), getLatestCommit())
}.size
} else 0
fun getVersion(): String = buildString {
if (grgit == null || getLatestCommit() == null) {
append("-nogit")
return@buildString
}
if (!grgit!!.status().isClean) {
append("-DEV")
return@buildString
}
val unreleasedCommits = getUnreleasedCommits()
if (grgit!!.branch.current().name != "master" || unreleasedCommits > 0) {
append("-SNAPSHOT")
if (unreleasedCommits > 0) {
append("+$unreleasedCommits")
}
}
append("-${getLatestCommit()!!.abbreviatedId}")
}
version = "$version${getVersion()}"
}
repositories {
mavenCentral()
if (System.getenv("CI")?.toBoolean() != true) {
maven("https://maven.aliyun.com/repository/public") // 阿里云国内代理仓库
}
maven("https://repo.papermc.io/repository/maven-public/") {
name = "PaperMC"
content {
includeGroup("com.velocitypowered")
}
}
maven("https://repo.opencollab.dev/main/") {
content {
includeGroupByRegex("org.geysermc.*")
}
}
maven("https://maven.msdnicrosoft.work/velocity/") {
content {
includeGroup("com.velocitypowered")
}
}
}
dependencies {
detektPlugins(libs.detekt.formatting)
compileOnly(libs.bundles.velocity)
compileOnly(libs.bundles.asm)
compileOnly(libs.floodgate)
compileOnly(libs.netty)
compileOnly(libs.fastutil)
implementation(libs.kaml)
implementation(libs.kotlin.serialization.json) { isTransitive = false }
implementation(libs.byte.buddy.agent)
implementation(libs.bundles.kavaref) { isTransitive = false }
}
detekt {
config.setFrom(project.rootDir.resolve("config/detekt/detekt.yml"))
buildUponDefaultConfig = true
parallel = true
autoCorrect = true
}
yamlang {
targetSourceSets = listOf(sourceSets.main.get())
inputDir = "lang"
}
tasks {
val runDir: File = project.rootDir.resolve("run")
build {
dependsOn(shadowJar)
}
jar {
archiveFileName = "${rootProject.name}-${rootProject.version}-unshaded.jar"
}
shadowJar {
minimizeJar = true
archiveClassifier = null
doFirst {
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
exclude("META-INF/proguard/**")
exclude("META-INF/com.android.tools/**")
}
relocate("kotlin", "avm.kotlin")
relocate("kotlinx.serialization", "avm.kotlinx.serialization")
relocate("com.charleskorn.kaml", "avm.com.charleskorn.kaml")
relocate("com.highcapable.kavaref", "avm.com.highcapable.kavaref")
}
processResources {
filesMatching("velocity-plugin.json") {
expand("version" to version)
}
}
compileJava {
targetCompatibility = "21"
}
compileKotlin {
dependsOn(detekt)
compilerOptions {
jvmTarget = JvmTarget.JVM_21
}
}
clean {
doLast {
runDir.deleteRecursively()
}
}
@Suppress("UNCHECKED_CAST")
val downloadVelocity by registering {
description = "Downloads the latest Velocity server JAR"
group = "velocity"
val version: String = libs.versions.velocity.get()
val velocityJar: File = file("$runDir/velocity-server-$version.jar")
val gson = Gson()
outputs.file(velocityJar)
doLast {
if (!runDir.exists()) runDir.mkdirs()
if (velocityJar.exists() && velocityJar.length() > 0) return@doLast
val buildsUrl: URL = URI("https://fill.papermc.io/v3/projects/velocity/versions/$version/builds").toURL()
val latestBuild: Map<String, Any> = gson
.fromJson<List<Map<String, Any>>>(buildsUrl.readText(), List::class.java)
.first()
val downloads: Map<String, Map<String, Any>> = latestBuild["downloads"] as Map<String, Map<String, Any>>
val serverDefault: Map<String, Any> = downloads["server:default"]!!
val downloadUrl: URL = URI(serverDefault["url"] as String).toURL()
println("Downloading Velocity server $version...")
try {
downloadUrl.openStream().use { input ->
velocityJar.outputStream().use { output ->
input.copyTo(output)
}
}
} catch (e: Exception) {
println("Failed to download Velocity server: ${e.message}")
throw e
}
}
}
val runVelocity by registering(JavaExec::class) {
dependsOn(shadowJar, downloadVelocity)
description = "Runs the velocity server."
group = "velocity"
val version: String = libs.versions.velocity.get()
val pluginsDir: File = file("run/plugins")
val velocityJar: File = file("$runDir/velocity-server-$version.jar")
standardInput = System.`in`
standardOutput = System.out
errorOutput = System.err
workingDir = runDir
doFirst {
if (!pluginsDir.exists()) pluginsDir.mkdirs()
val pluginJar: File = shadowJar.get().archiveFile.get().asFile
if (pluginJar.exists()) {
copy {
from(pluginJar)
into(pluginsDir)
}
}
if (!velocityJar.exists()) throw GradleException("Velocity server does not exist: ${velocityJar.absolutePath}")
}
mainClass = "com.velocitypowered.proxy.Velocity"
systemProperty("net.kyori.adventure.text.warnWhenLegacyFormattingDetected", true)
systemProperty("file.encoding", "UTF-8")
systemProperty("stdout.encoding", "UTF-8")
jvmArgs(
"-XX:+UseG1GC",
"-XX:G1HeapRegionSize=4M",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+ParallelRefProcEnabled",
"-XX:+AlwaysPreTouch",
"-XX:MaxInlineLevel=15"
)
classpath = files(velocityJar)
}
}