import org.gradle.api.JavaVersion import com.android.build.gradle.LibraryExtension import com.android.build.gradle.AppExtension allprojects { repositories { google() mavenCentral() } } allprojects { buildscript { repositories { google() mavenCentral() } } } allprojects { configurations.all { resolutionStrategy.eachDependency { if (requested.group == "org.ow2.asm" && requested.name == "asm-util") { useVersion("9.6") because("jcenter is deprecated, using mavenCentral version") } } } } // 统一设置 JVM 版本 allprojects { tasks.withType { sourceCompatibility = "17" targetCompatibility = "17" } tasks.withType { kotlinOptions { jvmTarget = "17" } } } // 为所有子项目(包括依赖的模块)设置统一的 JVM 目标版本 subprojects { tasks.withType { sourceCompatibility = "17" targetCompatibility = "17" } tasks.withType { kotlinOptions { jvmTarget = "17" } } } // 为所有模块设置统一的 JVM 目标版本 subprojects { afterEvaluate { // 为 Java 编译任务设置 JVM 版本 tasks.withType { sourceCompatibility = "17" targetCompatibility = "17" } // 为 Kotlin 编译任务设置 JVM 版本 tasks.withType { kotlinOptions { jvmTarget = "17" } } // 为 Android 模块设置编译选项 if (plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application")) { extensions.findByType()?.apply { compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } } extensions.findByType()?.apply { compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } } } } } val newBuildDir: Directory = rootProject.layout.buildDirectory .dir("../../build") .get() rootProject.layout.buildDirectory.value(newBuildDir) subprojects { val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) project.layout.buildDirectory.value(newSubprojectBuildDir) } subprojects { project.evaluationDependsOn(":app") } tasks.register("clean") { delete(rootProject.layout.buildDirectory) }