build.gradle 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. subprojects {
  2. apply plugin: 'java'
  3. apply plugin: 'idea'
  4. // 配置Java版本
  5. java {
  6. toolchain {
  7. languageVersion.set(JavaLanguageVersion.of(23)) // 设置 JDK 23
  8. }
  9. }
  10. repositories {
  11. // 优先使用本地 Maven 缓存
  12. mavenLocal()
  13. // 阿里云公共仓库
  14. maven { url "https://maven.aliyun.com/repository/public" }
  15. // 阿里云 Gradle 插件仓库
  16. maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
  17. // 官方仓库作为备用
  18. mavenCentral()
  19. }
  20. // 配置编译选项
  21. tasks.withType(JavaCompile).configureEach {
  22. options.encoding = 'UTF-8'
  23. options.incremental = true // 启用增量编译
  24. // 启用现代编译参数
  25. options.compilerArgs.addAll([
  26. '--enable-preview', // 启用预览特性
  27. '-parameters' // 保留方法参数名
  28. ])
  29. }
  30. // 现代任务注册方式
  31. tasks.register('copyAllDependencies', Copy) {
  32. group = 'Build'
  33. description = 'Copies all dependencies to lib directory'
  34. from configurations.runtimeClasspath
  35. into layout.buildDirectory.dir("libs/lib") // 使用现代路径 API
  36. // 添加分类器过滤(可选)
  37. include '*.jar'
  38. exclude '*-sources.jar', '*-javadoc.jar'
  39. }
  40. // 构建后自动复制依赖(按需启用)
  41. tasks.named('build') {
  42. finalizedBy tasks.named('copyAllDependencies')
  43. }
  44. // 测试配置现代化
  45. tasks.named('test', Test) {
  46. useJUnitPlatform()
  47. maxHeapSize = '2G'
  48. // 并行测试配置
  49. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  50. forkEvery = 100
  51. }
  52. }