subprojects { apply plugin: 'java' apply plugin: 'idea' // 配置Java版本 java { toolchain { languageVersion.set(JavaLanguageVersion.of(23)) // 设置 JDK 23 } } repositories { // 优先使用本地 Maven 缓存 mavenLocal() // 阿里云公共仓库 maven { url "https://maven.aliyun.com/repository/public" } // 阿里云 Gradle 插件仓库 maven { url "https://maven.aliyun.com/repository/gradle-plugin" } // 官方仓库作为备用 mavenCentral() } // 配置编译选项 tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' options.incremental = true // 启用增量编译 // 启用现代编译参数 options.compilerArgs.addAll([ '--enable-preview', // 启用预览特性 '-parameters' // 保留方法参数名 ]) } // 现代任务注册方式 tasks.register('copyAllDependencies', Copy) { group = 'Build' description = 'Copies all dependencies to lib directory' from configurations.runtimeClasspath into layout.buildDirectory.dir("libs/lib") // 使用现代路径 API // 添加分类器过滤(可选) include '*.jar' exclude '*-sources.jar', '*-javadoc.jar' } // 构建后自动复制依赖(按需启用) tasks.named('build') { finalizedBy tasks.named('copyAllDependencies') } // 测试配置现代化 tasks.named('test', Test) { useJUnitPlatform() maxHeapSize = '2G' // 并行测试配置 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 forkEvery = 100 } }