|
@@ -1,46 +1,50 @@
|
|
|
plugins {
|
|
|
- id 'java'
|
|
|
- id 'application'
|
|
|
- id 'com.github.johnrengelman.shadow' version "8.1.1"
|
|
|
+ id("java")
|
|
|
+ id("application")
|
|
|
+ id("com.github.johnrengelman.shadow") version "8.1.1"
|
|
|
}
|
|
|
|
|
|
-group = 'com.incubator.app'
|
|
|
-version = '1.0-SNAPSHOT'
|
|
|
+group = "com.incubator.app"
|
|
|
|
|
|
// 项目依赖
|
|
|
dependencies {
|
|
|
// 子模块依赖
|
|
|
- implementation project(':incubator-game')
|
|
|
+ implementation project(":incubator-game")
|
|
|
|
|
|
// 测试依赖
|
|
|
- testImplementation platform("org.junit:junit-bom:5.10.0")
|
|
|
- testImplementation "org.junit.jupiter:junit-jupiter-api"
|
|
|
- testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
|
|
|
+ testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
|
|
|
+ testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
|
|
|
}
|
|
|
|
|
|
// 使用 Gradle 的现代 API 定义源集
|
|
|
sourceSets {
|
|
|
- main {
|
|
|
+ conf {
|
|
|
resources {
|
|
|
- srcDirs = ['conf'] // 移除 += 以明确覆盖默认值
|
|
|
+ srcDirs("conf")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
application {
|
|
|
// 类型安全的主类配置
|
|
|
- mainClass = "App"
|
|
|
+ mainClass = "com.incubator.app.App"
|
|
|
|
|
|
// 配置 JVM 参数,支持高并发和性能优化
|
|
|
applicationDefaultJvmArgs = [
|
|
|
- "-XX:+UseZGC", // 使用 ZGC 垃圾回收器,适合高并发
|
|
|
- "-Xmx2G", // 限制最大堆大小
|
|
|
- "-XX:+UnlockExperimentalVMOptions", // 启用实验性选项
|
|
|
- "-XX:ZUncommitDelay=300", // 减少内存未使用时的延迟
|
|
|
- "-XX:+HeapDumpOnOutOfMemoryError", // OOM 时生成堆转储
|
|
|
- "-XX:ZCollectionInterval=3",
|
|
|
- "-Dio.netty.allocator.numDirectArenas=0", // 禁用堆外内存
|
|
|
- "-Dio.netty.leakDetection.level=PARANOID"
|
|
|
+ "-XX:+UseZGC", // 启用 ZGC 垃圾回收器,低延迟适合高并发
|
|
|
+ "-XX:+ZGenerational", // 开启分代 ZGC 模式,优化GC性能
|
|
|
+ "-XX:MaxRAMPercentage=70", // JVM 最大内存占用为系统内存的70%
|
|
|
+ "-XX:-ZUncommit", // 禁止 JVM 主动归还未使用内存给系统
|
|
|
+ "-XX:+AlwaysPreTouch", // JVM 启动时预先分配所有堆内存,加速运行时性能
|
|
|
+ "-XX:+HeapDumpOnOutOfMemoryError", // 内存溢出时自动生成堆转储文件,用于诊断
|
|
|
+ "-XX:HeapDumpPath=heapdump.hprof", // 指定堆转储文件的保存路径
|
|
|
+ "-Dfile.encoding=UTF-8", // 设置文件默认字符编码为 UTF-8
|
|
|
+ "-Djava.security.egd=file:/dev/./urandom", // 使用非阻塞随机数生成器,加快启动
|
|
|
+ "-Dnetworkaddress.cache.ttl=10", // DNS缓存有效时间设为10秒,避免长时间缓存问题
|
|
|
+ "-Dsun.net.client.defaultConnectTimeout=60000", // 默认网络连接超时时间设为60秒
|
|
|
+ "-Dsun.net.client.defaultReadTimeout=60000", // 默认网络读取超时时间设为60秒
|
|
|
+ "-Djava.awt.headless=true", // 启用无头模式,避免图形界面环境相关问题
|
|
|
+ "-Dio.netty.tryReflectionSetAccessible=true" // Netty启用反射访问,以提高Java高版本兼容性与性能
|
|
|
]
|
|
|
}
|
|
|
|
|
@@ -49,7 +53,7 @@ tasks.withType(JavaCompile).configureEach {
|
|
|
}
|
|
|
|
|
|
// 禁用默认的 JAR 任务,因为我们使用 Shadow JAR
|
|
|
-tasks.named('jar') {
|
|
|
+tasks.jar {
|
|
|
enabled = false
|
|
|
}
|
|
|
|
|
@@ -57,23 +61,23 @@ tasks.named('jar') {
|
|
|
tasks.shadowJar {
|
|
|
zip64 = true
|
|
|
// 设置 JAR 包的基本名称
|
|
|
- archiveBaseName = 'incubator-app'
|
|
|
+ archiveBaseName.set("incubator-app")
|
|
|
// 使用项目的版本号作为 JAR 的版本
|
|
|
- archiveVersion = project.version
|
|
|
+ archiveVersion.set(project.version.toString())
|
|
|
// 移除分类器,生成的 JAR 没有后缀
|
|
|
- archiveClassifier = ''
|
|
|
+ archiveClassifier.set("")
|
|
|
|
|
|
// 添加自定义清单
|
|
|
manifest {
|
|
|
// 使用动态设置的主类
|
|
|
- attributes 'Main-Class': application.mainClass.get()
|
|
|
+ attributes("Main-Class": application.mainClass.get())
|
|
|
}
|
|
|
|
|
|
// 将 conf 目录包含到最终的 JAR 文件中
|
|
|
- from('conf') { into('conf') }
|
|
|
+ from("conf") { into("conf") }
|
|
|
|
|
|
// 可选:排除不必要的依赖
|
|
|
- exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
|
|
|
+ exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
|
|
|
|
|
|
// 避免重复打包无关的文件
|
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
@@ -89,8 +93,8 @@ tasks.test {
|
|
|
}
|
|
|
|
|
|
// 将 Shadow JAR 绑定到 assemble 阶段
|
|
|
-tasks.named('assemble') {
|
|
|
- dependsOn tasks.named = 'shadowJar' as Task
|
|
|
+tasks.named("assemble") {
|
|
|
+ dependsOn(tasks.named("shadowJar"))
|
|
|
}
|
|
|
|
|
|
// 增加构建信息任务
|
|
@@ -109,6 +113,6 @@ tasks.register("buildInfo") {
|
|
|
}
|
|
|
|
|
|
// 清理任务优化
|
|
|
-tasks.named('clean') {
|
|
|
+tasks.named("clean", Delete).configure {
|
|
|
delete(layout.buildDirectory)
|
|
|
}
|