|
@@ -1,7 +1,7 @@
|
|
|
plugins {
|
|
|
id 'java'
|
|
|
id 'application'
|
|
|
- id "com.github.johnrengelman.shadow" version "7.1.2"
|
|
|
+ id "com.github.johnrengelman.shadow" version "8.1.1"
|
|
|
}
|
|
|
|
|
|
group = 'com.incubator.game'
|
|
@@ -19,13 +19,15 @@ application {
|
|
|
// 使用新的方法设置主类,适应 Gradle 7.0 及以上版本
|
|
|
mainClass.set('com.incubator.game.GameServerStart')
|
|
|
|
|
|
- // 添加 JVM 参数,指定 conf 目录下的配置文件路径
|
|
|
+ // 配置 JVM 参数,支持高并发和性能优化
|
|
|
applicationDefaultJvmArgs = [
|
|
|
- "-Dlog4j.configurationFile=conf/log4j2.xml",
|
|
|
- "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", // 启用远程调试
|
|
|
- "-XX:+UseG1GC", // 使用 G1 GC
|
|
|
- "-XX:MaxGCPauseMillis=200", // 控制 GC 停顿时间
|
|
|
- "-XX:+HeapDumpOnOutOfMemoryError" // 发生 OOM 时生成堆转储
|
|
|
+ "-XX:+UseZGC", // 使用 ZGC 垃圾回收器,适合高并发
|
|
|
+ "-XX:+UnlockExperimentalVMOptions", // 启用实验性选项
|
|
|
+ "-XX:ZUncommitDelay=300", // 减少内存未使用时的延迟
|
|
|
+ "-XX:MaxHeapSize=2G", // 限制最大堆大小
|
|
|
+ "-XX:+HeapDumpOnOutOfMemoryError", // OOM 时生成堆转储
|
|
|
+ "--enable-preview", // 启用 Java 23 的预览功能
|
|
|
+ "-Dlog4j.configurationFile=conf/log4j2.xml"
|
|
|
]
|
|
|
}
|
|
|
|
|
@@ -51,9 +53,7 @@ tasks.shadowJar {
|
|
|
}
|
|
|
|
|
|
// 将 conf 目录包含到最终的 JAR 文件中
|
|
|
- from('conf') {
|
|
|
- into('conf') // 指定 JAR 内的路径
|
|
|
- }
|
|
|
+ from('conf') { into('conf') }
|
|
|
|
|
|
// 可选:排除不必要的依赖
|
|
|
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
|
|
@@ -62,20 +62,14 @@ tasks.shadowJar {
|
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
|
}
|
|
|
|
|
|
-// 依赖版本集中管理
|
|
|
-ext {
|
|
|
- junitVersion = '5.9.0'
|
|
|
- shadowVersion = '7.1.2'
|
|
|
-}
|
|
|
-
|
|
|
// 项目依赖
|
|
|
dependencies {
|
|
|
// 子模块依赖
|
|
|
implementation project(':incubator-core')
|
|
|
|
|
|
// 测试依赖
|
|
|
- testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
|
|
|
- testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
|
|
|
+ testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
|
|
|
+ testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
|
|
|
}
|
|
|
|
|
|
// 配置测试任务
|
|
@@ -84,6 +78,7 @@ tasks.test {
|
|
|
testLogging {
|
|
|
events 'PASSED', 'FAILED', 'SKIPPED'
|
|
|
}
|
|
|
+ maxParallelForks = Runtime.runtime.availableProcessors() // 并行测试
|
|
|
}
|
|
|
|
|
|
// 将 Shadow JAR 绑定到 assemble 阶段
|
|
@@ -92,13 +87,14 @@ tasks.assemble.dependsOn(tasks.shadowJar)
|
|
|
// 增加构建信息任务
|
|
|
tasks.register("buildInfo") {
|
|
|
doLast {
|
|
|
- println "Building project '${project.name}' version '${project.version}'"
|
|
|
+ println "Building project '${project.name}'"
|
|
|
+ println "Version '${project.version}'"
|
|
|
println "Main class: ${application.mainClass.get()}"
|
|
|
- println "Shadow JAR: ${tasks.shadowJar.get().archiveFile.get()}"
|
|
|
+ println "Shadow JAR: ${tasks.shadowJar.get().archiveFile.get().asFile.absolutePath}"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 清理任务优化
|
|
|
tasks.clean {
|
|
|
- delete "$buildDir/libs" // 确保清理构建目录
|
|
|
+ delete layout.buildDirectory.get().asFile // 使用现代 API 清理构建目录
|
|
|
}
|