build.gradle 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. subprojects {
  2. apply plugin: 'java'
  3. apply plugin: 'idea'
  4. // 配置Java版本
  5. java {
  6. toolchain {
  7. languageVersion.set(JavaLanguageVersion.of(8)) // 设置 JDK 8
  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. // 任务:复制所有依赖到指定目录
  26. tasks.register('copyAllDependencies', Copy) {
  27. description = 'Copies all runtime dependencies to the libs directory'
  28. group = 'build' // 将任务归类到构建任务组中
  29. from(configurations.runtimeClasspath) // 使用 runtimeClasspath
  30. into("${buildDir}/libs/lib")
  31. }
  32. // 可选:启用 Gradle 缓存和并行化构建
  33. gradle.projectsEvaluated {
  34. tasks.withType(JavaCompile).configureEach {
  35. options.fork = true // 启用编译器分叉,提高性能
  36. }
  37. }
  38. }