-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbuild.gradle.kts
408 lines (342 loc) · 14.8 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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.vanniktech.maven.publish.SonatypeHost
import org.apache.tools.ant.filters.ReplaceTokens
import de.undercouch.gradle.tasks.download.Download
plugins {
java
id("de.undercouch.download") version "5.6.0"
id("io.freefair.lombok") version "8.11"
// Including dependencies in final jar
id("com.gradleup.shadow") version "8.3.5"
id("com.vanniktech.maven.publish") version "0.30.0"
}
object DepData {
const val JAVA_VERSION = 21
const val LIVE_VERSION = "0.0.25-FIX3"
const val THIS_VERSION = "0.0.26-SNAPSHOT1"
const val PLUGIN_NAME = "ClaimChunk"
const val ARCHIVES_BASE_NAME = "claimchunk"
const val MAIN_CLASS = "com.cjburkey.claimchunk.ClaimChunk"
// Only used if you run `gradlew installSpigot`
const val SPIGOT_BUILD_TOOLS_URL
= "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
const val SPIGOT_REV = "1.21"
// Dependency versions
const val SPIGOT_VERSION = "1.21.3-R0.1-SNAPSHOT"
const val LATEST_MC_VERSION = "1.21.4"
const val VAULT_API_VERSION = "1.7.1"
const val WORLD_EDIT_CORE_VERSION = "7.3.9"
const val WORLD_GUARD_BUKKIT_VERSION = "7.0.12"
const val PLACEHOLDER_API_VERSION = "2.11.6"
const val JETBRAINS_ANNOTATIONS_VERSION = "24.1.0"
const val JUNIT_VERSION = "5.10.3"
const val JUNIT_LAUNCHER_VERSION = "1.10.3"
const val SQLITE_JDBC_VERSION = "3.42.0.1"
const val JAVAX_PERSISTENCE_VERSION = "2.1.0"
const val JAVAX_TRANSACTION_VERSION = "1.1"
const val SANS_ORM_VERSION = "3.17"
const val SLF4J_VERSION = "1.7.25"
const val BSTATS_VERSION = "3.0.2"
const val SORMULA_VERSION = "4.3"
const val MOCK_BUKKIT_VERSION = "4.21.0"
// Directories
const val TEST_SERVER_DIR = "run"
const val OUTPUT_DIR = "OUT"
// Readme locations
const val README_IN = "unbuilt_readme.md"
const val README_OUT = "README.md"
}
// Tokens to replace within files
val replaceTokens = mapOf(
"tokens" to mapOf(
"PLUGIN_VERSION" to DepData.THIS_VERSION,
"JAVA_VERSION" to DepData.JAVA_VERSION.toString(),
"MAIN_CLASS" to DepData.MAIN_CLASS,
"PLUGIN_NAME" to DepData.PLUGIN_NAME,
"LIVE_VERSION" to DepData.LIVE_VERSION,
"SPIGOT_VERSION" to DepData.SPIGOT_VERSION.substring(0, DepData.SPIGOT_VERSION.indexOf("-")),
"LATEST_MC_VERSION" to DepData.LATEST_MC_VERSION
)
)
// Plugin information
group = "com.cjburkey.claimchunk"
version = DepData.THIS_VERSION
val mainDir = layout.projectDirectory
java {
toolchain {
languageVersion = JavaLanguageVersion.of(DepData.JAVA_VERSION)
}
}
tasks {
compileJava {
mustRunAfter("googleFormat")
// Disable incremental compilation (module system bs and spigot no mesh
// well)
options.isIncremental = false
// Enable all compiler warnings for cleaner (hopefully) code
options.isWarnings = true
options.isDeprecation = true
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Xmaxwarns", "200"))
options.encoding = "UTF-8"
}
// We don't actually include any other libraries now
// (except smartcommanddispatcher, but we do that manually)
shadowJar {
mustRunAfter("googleFormat", "updateReadme")
// Set the jar name and version
archiveBaseName.set(DepData.ARCHIVES_BASE_NAME)
archiveClassifier.set("plugin")
archiveVersion.set(project.version.toString())
minimize {
exclude("org/apache/log4j/**")
exclude("*.html")
}
// Imma die
dependencies {
exclude {
it.moduleGroup == "org.apache"
|| it.moduleGroup == "org.slf4j"
}
exclude(dependency("org.slf4j:slf4j-api"))
exclude(dependency("org.slf4j:slf4j-simple"))
exclude(dependency("org.apache.log4j:"))
exclude(dependency("org.xerial:sqlite-jdbc"))
exclude(dependency("org.jetbrains:annotations"))
}
relocate("com.zaxxer", "claimchunk.dependency.com.zaxxer")
relocate("javax.persistence", "claimchunk.dependency.javax.persistence")
relocate("javax.transaction", "claimchunk.dependency.javax.transaction")
relocate("org.eclipse", "claimchunk.dependency.org.eclipse")
relocate("org.osgi", "claimchunk.dependency.org.osgi")
relocate("org.bstats", "claimchunk.dependency.org.bstats")
relocate("org.sormula", "claimchunk.dependency.org.sormula")
}
register<Delete>("cleanTests") {
delete(fileTree(mainDir).include("tmp/*.tmp.sqlite3"))
}
test {
useJUnitPlatform()
systemProperties = mapOf(
"junit.jupiter.conditions.deactivate" to "*",
"junit.jupiter.extensions.autodetection.enabled" to "true",
"junit.jupiter.testinstance.lifecycle.default" to "per_class"
)
finalizedBy("cleanTests")
}
clean {
// Delete old build(s)
project.delete(files(DepData.OUTPUT_DIR))
// Delete old build(s) from test server plugin dir
project.delete(
fileTree(mainDir.dir("${DepData.TEST_SERVER_DIR}/plugins"))
.include("claimchunk**.jar")
.include("ClaimChunk**.jar"))
}
build {
mustRunAfter("googleFormat", "clean")
dependsOn("jar")
// When the build task is run, copy the version into the testServerDir and output
// (Also rebuild the README file)
finalizedBy("updateReadme",
"copyClaimChunkToOutputDir"
)
}
// Replace placeholders with values in source and resource files
processResources {
filter<ReplaceTokens>(replaceTokens)
}
// Fill in readme placeholders
register<Copy>("updateReadme") {
mustRunAfter("build")
description = "Expands tokens in the unbuilt readme file into the main readme file"
val inf = mainDir.file(DepData.README_IN)
val ouf = mainDir.file(DepData.README_OUT)
doFirst {
closureOf<Delete> {
inputs.file(ouf)
delete(ouf)
}
}
// Set the inputs and outputs for the operation
inputs.file(inf)
outputs.file(ouf)
// Copy the new readme, rename it, and expand tokens
from(inf)
into(mainDir)
filter<ReplaceTokens>(replaceTokens)
rename(DepData.README_IN, DepData.README_OUT)
}
// Clear out old Spigot versions from test server directory
register<Delete>("deleteOldSpigotInstalls") {
description = "Deletes (any) old Spigot server jars from the test server directory"
delete(fileTree(mainDir.dir(DepData.TEST_SERVER_DIR)).include("spigot-*.jar"))
}
register<Download>("downloadSpigotBuildTools") {
description = "Downloads the latest version of the Spigot BuildTools into TEST_SERVER_DIR/TEMP"
src(DepData.SPIGOT_BUILD_TOOLS_URL)
dest(mainDir.dir(DepData.TEST_SERVER_DIR).dir("TEMP").file("BuildTools.jar"))
overwrite(true)
}
// Download and run Spigot BuildTools to generate a Spigot server jar in the spigot `testServerDir`
register<JavaExec>("installSpigot") {
description = "Downloads and executes the Spigot build tools to generate a server jar in the test server directory."
// Delete old Spigot jar(s) and download BuildTools first
dependsOn("deleteOldSpigotInstalls", "downloadSpigotBuildTools")
val testServerDir = mainDir.dir(DepData.TEST_SERVER_DIR)
val tmpDir = testServerDir.dir("TEMP")
val tmpServerJar = tmpDir.file("spigot-${DepData.SPIGOT_REV}.jar")
// Run the build tools jar (the manifest main class)
mainClass.set("-jar")
workingDir(tmpDir)
args("BuildTools.jar", "--nogui", "--rev", DepData.SPIGOT_REV)
doLast {
println("Cleaning up Spigot build")
tmpServerJar.asFile.copyTo(testServerDir.file("spigot-${DepData.SPIGOT_REV}.jar").asFile, true)
tmpDir.asFile.deleteRecursively()
}
}
// Copy from the libs dir to the plugins directory in the testServerDir
register<Copy>("copyClaimChunkToPluginsDir") {
dependsOn("copyClaimChunkToOutputDir")
description = "Copies ClaimChunk from the build directory to the test server plugin directory."
from(shadowJar)
into(mainDir.dir("${DepData.TEST_SERVER_DIR}/plugins"))
}
register<Copy>("copyClaimChunkToOutputDir") {
mustRunAfter("clean", "build", "updateReadme")
description = "Copies ClaimChunk from the build directory to the output directory."
from(shadowJar)
into(mainDir.dir(DepData.OUTPUT_DIR))
}
register<JavaExec>("googleFormat") {
description = "Attempts to format source files for ClaimChunk to unify programming style."
// For now, this file is just included with the project for the sake of
// ease of use.
val execJarFile = mainDir.file("req/google-java-format-1.22.0-all-deps.jar")
// Include all source Java files
// (I don't think there's a case where I would want to avoid formatting
// a file, but be it necessary, this is where it would be implemented)
val includedFiles = fileTree("src") {
include("**/*.java")
}.files
inputs.files(includedFiles)
outputs.files(includedFiles)
// Run the build tools jar (the manifest main class)
// The JVM args are required because of Java's Project Jigsaw
mainClass.set("-jar")
workingDir(mainDir)
jvmArgs("--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED")
jvmArgs("--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED")
jvmArgs("--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED")
jvmArgs("--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED")
jvmArgs("--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")
args(execJarFile)
args("--replace")
args("--aosp")
args(includedFiles)
}
}
task<Jar>("sourcesJar").mustRunAfter("googleFormat")
// -- DEPENDENCIES -- //
// Extra repos for Bukkit/Spigot stuff
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
maven("https://maven.enginehub.org/repo/")
maven("https://repo.mikeprimm.com")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://jitpack.io")
}
dependencies {
// Things needed to compile the plugin
compileOnly("org.jetbrains:annotations:${DepData.JETBRAINS_ANNOTATIONS_VERSION}")
compileOnly("org.spigotmc:spigot-api:${DepData.SPIGOT_VERSION}")
compileOnly("com.github.MilkBowl:VaultAPI:${DepData.VAULT_API_VERSION}")
compileOnly("com.sk89q.worldedit:worldedit-core:${DepData.WORLD_EDIT_CORE_VERSION}")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:${DepData.WORLD_GUARD_BUKKIT_VERSION}")
compileOnly("me.clip:placeholderapi:${DepData.PLACEHOLDER_API_VERSION}")
// We need these during runtime!
implementation("org.xerial:sqlite-jdbc:${DepData.SQLITE_JDBC_VERSION}")
implementation("org.eclipse.persistence:javax.persistence:${DepData.JAVAX_PERSISTENCE_VERSION}")
implementation("javax.transaction:transaction-api:${DepData.JAVAX_TRANSACTION_VERSION}")
implementation("com.github.h-thurow:q2o:${DepData.SANS_ORM_VERSION}")
implementation("org.bstats:bstats-bukkit:${DepData.BSTATS_VERSION}")
implementation("org.sormula:sormula:${DepData.SORMULA_VERSION}")
testImplementation("org.slf4j:slf4j-simple:${DepData.SLF4J_VERSION}")
testImplementation("org.junit.jupiter:junit-jupiter:${DepData.JUNIT_VERSION}")
testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:${DepData.MOCK_BUKKIT_VERSION}")
// testImplementation("org.spigotmc:spigot-api:${DepData.SPIGOT_VERSION}")
testImplementation("io.papermc.paper:paper-api:${DepData.SPIGOT_VERSION}")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:${DepData.JUNIT_LAUNCHER_VERSION}")
}
// -- Publishing! -- //
// https://vanniktech.github.io/gradle-maven-publish-plugin/central/
mavenPublishing {
// publishing to https://central.sonatype.com/
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
signAllPublications()
coordinates("com.cjburkey.claimchunk", DepData.ARCHIVES_BASE_NAME, DepData.THIS_VERSION)
pom {
name.set(DepData.PLUGIN_NAME)
description.set("Spigot/Paper plugin allowing players to claim chunks")
inceptionYear.set("2017")
url.set("https://github.com/cjburkey01/ClaimChunk")
licenses {
license {
name.set("MIT License")
url.set("https://github.com/cjburkey01/ClaimChunk/blob/main/LICENSE")
distribution.set("https://github.com/cjburkey01/ClaimChunk/blob/main/LICENSE")
}
}
developers {
developer {
id.set("cjburkey01")
name.set("CJ Burkey")
url.set("https://github.com/cjburkey01/")
}
developer {
id.set("Goldmensch")
name.set("Goldmensch")
url.set("https://github.com/Goldmensch")
}
developer {
id.set("DeathsGun")
name.set("DeathsGun")
url.set("https://github.com/DeathsGun")
}
developer {
id.set("T0biii")
name.set("T0biii")
url.set("https://github.com/T0biii")
}
developer {
id.set("Geolykt")
name.set("Geolykt")
url.set("https://github.com/Geolykt")
}
developer {
id.set("JustDoom")
name.set("JustDoom")
url.set("https://github.com/JustDoom")
}
developer {
id.set("AlexFF000")
name.set("AlexFF000")
url.set("https://github.com/AlexFF000")
}
developer {
id.set("18PatZ")
name.set("18PatZ")
url.set("https://github.com/18PatZ")
}
}
scm {
url.set("https://github.com/cjburkey01/ClaimChunk")
connection.set("scm:git:git://github.com/cjburkey01/ClaimChunk.git")
developerConnection.set("scm:git:ssh://[email protected]/cjburkey01/ClaimChunk.git")
}
}
}