forked from PowerNukkitX/PowerNukkitX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
351 lines (302 loc) · 9.87 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
351 lines (302 loc) · 9.87 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
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
import java.nio.charset.StandardCharsets
// Explicit Gradle API imports to fix Kotlin DSL unresolved references
import org.gradle.external.javadoc.CoreJavadocOptions
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Copy
import org.gradle.api.publish.maven.MavenPublication
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.testing.jacoco.tasks.JacocoReport
plugins {
`java-library`
`maven-publish`
java
idea
jacoco
id("io.github.goooler.shadow") version "8.1.7"
id("io.freefair.lombok") version "8.4"
id("com.gorylenko.gradle-git-properties") version "2.5.5"
}
group = "org.powernukkitx"
version = "2.0.0-SNAPSHOT"
description = "powernukkitx"
java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21
// Constants
val SHADOW_JAR = "shadowJar"
val ENCODING = "UTF-8"
val GH_BUILD = "build"
val ALPHA_BUILD = "alpha build"
dependencies {
api(libs.bundles.netty)
api(libs.bundles.logging)
api(libs.annotations)
api(libs.jsr305)
api(libs.gson)
api(libs.guava)
api(libs.commonsio)
api(libs.fastutil)
api(libs.snakeyaml)
api(libs.stateless4j)
implementation(libs.bundles.leveldb)
implementation(libs.rng.simple)
implementation(libs.rng.sampling)
implementation(libs.asm)
implementation(libs.jose4j)
implementation(libs.joptsimple)
implementation(libs.disruptor)
implementation(libs.oshi)
implementation(libs.fastreflection)
implementation(libs.terra)
implementation(libs.bundles.compress)
implementation(libs.bundles.terminal)
implementation(libs.okaeri)
testImplementation(libs.bundles.test)
testImplementation(libs.commonsio)
testImplementation(libs.commonslang3)
testRuntimeOnly(libs.junit.platform.launcher)
compileOnly(libs.lombok)
annotationProcessor(libs.lombok)
testCompileOnly(libs.lombok)
testAnnotationProcessor(libs.lombok)
}
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(10, TimeUnit.MINUTES)
cacheChangingModulesFor(10, TimeUnit.MINUTES)
preferProjectModules()
}
}
tasks.withType<JavaCompile>().configureEach {
options.annotationProcessorPath = configurations.getByName("annotationProcessor")
}
java {
withSourcesJar()
withJavadocJar()
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
//Automatically download dependencies source code
idea {
module {
isDownloadSources = true
isDownloadJavadoc = false
excludeDirs.addAll(listOf(
file(".gradle"),
file("build"),
file("out")
))
}
}
sourceSets {
main {
resources {
srcDirs("src/main/resources")
}
}
}
tasks.processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.processTestResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.register<DefaultTask>("buildFast") {
group = ALPHA_BUILD
description = "Fast build without documentation and tests - for rapid development"
dependsOn(tasks.compileJava, tasks.processResources, tasks.classes, tasks.jar)
}
tasks.register<DefaultTask>("buildSkipChores") {
group = ALPHA_BUILD
description = "Build without documentation and tests"
dependsOn(tasks.compileJava, tasks.processResources, tasks.classes, tasks.jar, SHADOW_JAR)
}
tasks.register<DefaultTask>("buildForGithubAction") {
group = GH_BUILD
description = "Optimized build for CI/CD pipelines (without tests)"
dependsOn(tasks.compileJava, tasks.processResources, tasks.classes, tasks.jar, SHADOW_JAR)
}
tasks.build {
dependsOn(SHADOW_JAR)
group = ALPHA_BUILD
}
tasks.clean {
group = ALPHA_BUILD
description = "Deletes the build directory and generated files"
delete("pnx.yml", "terra", "services")
}
tasks.compileJava {
options.encoding = ENCODING
options.compilerArgs.addAll(listOf(
"-Xpkginfo:always",
"-parameters",
"-Xlint:-options",
"-Xlint:deprecation",
"-Xlint:unchecked"
))
options.isIncremental = true
options.isFork = true
options.forkOptions.jvmArgs = listOf("-Xmx2g")
options.release.set(21)
java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21
}
tasks.compileTestJava {
options.encoding = ENCODING
options.isIncremental = true
options.isFork = true
options.forkOptions.jvmArgs = listOf("-Xmx1g")
}
tasks.test {
useJUnitPlatform()
jvmArgs(
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.io=ALL-UNNAMED",
"-Xmx1g", // Limit test JVM memory
"-XX:+UseG1GC", // Use G1GC for tests
"-XX:MaxGCPauseMillis=200" // Lower GC pause time
)
// Performance for tests
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
forkEvery = 100 // Fork new JVM after 100 tests
// Test settings
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = false
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = false
}
finalizedBy("jacocoTestReport") // report is always generated after tests run
}
tasks.named<JacocoReport>("jacocoTestReport") {
reports {
csv.required = false
xml.required = true
html.required = false
}
dependsOn("test") // tests are required to run before generating the report
}
tasks.withType<AbstractCopyTask>() {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.named<AbstractArchiveTask>("sourcesJar") {
destinationDirectory.set(layout.buildDirectory)
}
// Improve build reproducibility for better caching
tasks.withType<AbstractArchiveTask> {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
tasks.named<ShadowJar>("shadowJar") {
dependsOn("copyDependencies")
manifest {
attributes(
"Main-Class" to "cn.nukkit.JarStart",
"Implementation-Version" to project.version,
"Implementation-Title" to project.name,
"Multi-Release" to "true"
)
}
// Required to fix shadowJar log4j2 plugin caching issue
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer::class.java)
// Minimize JAR size by excluding unnecessary files
exclude(
"META-INF/*.SF",
"META-INF/*.DSA",
"META-INF/*.RSA",
"META-INF/DEPENDENCIES",
"META-INF/LICENSE*",
"META-INF/NOTICE*",
"META-INF/maven/**",
"about.html"
)
// Merge service files for better compatibility
mergeServiceFiles()
destinationDirectory.set(layout.buildDirectory)
archiveFileName.set("${project.description}.jar")
// Enable ZIP64 format for large archives (>4GB)
isZip64 = true
}
tasks.register<Copy>("copyDependencies") {
dependsOn(tasks.jar)
group = "other"
description = "Copy all dependencies to libs folder"
from(configurations.runtimeClasspath)
into(layout.buildDirectory.dir("libs"))
// Enable up-to-date checking for better incremental builds
duplicatesStrategy = DuplicatesStrategy.INCLUDE
// Performance: Only copy if dependencies changed
inputs.files(configurations.runtimeClasspath)
outputs.dir(layout.buildDirectory.dir("libs"))
}
tasks.javadoc {
options.encoding = StandardCharsets.UTF_8.name()
includes.add("**/**.java")
val javadocOptions = options as CoreJavadocOptions
javadocOptions.addStringOption(
"source",
java.sourceCompatibility.toString()
)
// Suppress some meaningless warnings
javadocOptions.addStringOption("Xdoclint:none", "-quiet")
// Performance: Only generate javadoc for public API
javadocOptions.addBooleanOption("public", true)
// Enable parallel processing
isFailOnError = false
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifactId = "server"
pom {
url.set("https://github.com/PowerNukkitX/PowerNukkitX")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
scm {
connection.set("scm:git:git://github.com/PowerNukkitX/PowerNukkitX.git")
developerConnection.set("scm:git:ssh://github.com/PowerNukkitX/PowerNukkitX.git")
url.set("https://github.com/PowerNukkitX/PowerNukkitX")
}
}
}
}
repositories {
maven {
name = "pnx"
url = uri("https://repo.powernukkitx.org/releases")
credentials {
username = providers.gradleProperty("pnxUsername")
.orElse(providers.environmentVariable("PNX_REPO_USERNAME"))
.orNull
password = providers.gradleProperty("pnxPassword")
.orElse(providers.environmentVariable("PNX_REPO_PASSWORD"))
.orNull
}
}
}
}
tasks.withType<JavaCompile> {
options.encoding = ENCODING
}
tasks.withType<Javadoc> {
options.encoding = ENCODING
}
// Task optimization - disable unnecessary tasks for faster builds
tasks.configureEach {
// Skip tasks that aren't needed for standard builds
if (name.contains("delombok") && !gradle.startParameter.taskNames.contains("javadoc")) {
enabled = false
}
}