tasq/android/build.gradle.kts

93 lines
3.4 KiB
Plaintext

import com.android.build.gradle.LibraryExtension
import org.gradle.api.tasks.Delete
import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
allprojects {
repositories {
google()
mavenCentral()
}
}
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)
}
// Force compileSdk, Java 17, and Kotlin JVM target 17 on all library subprojects.
// Must use the `subprojects {}` block (not `subprojects.forEach`) so the
// afterEvaluate callback is registered *before* evaluationDependsOn triggers.
subprojects {
afterEvaluate {
plugins.withId("com.android.library") {
val androidExt = extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
try {
val sdkNum = androidExt.compileSdkVersion?.removePrefix("android-")?.toIntOrNull() ?: 0
if (sdkNum < 36) {
androidExt.compileSdkVersion("android-36")
}
} catch (_: Throwable) {}
}
// Align Kotlin JVM target with Java 17 to avoid mismatch errors
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
}
}
plugins.withId("com.android.application") {
val androidExt = extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
}
}
}
}
subprojects {
project.evaluationDependsOn(":app")
}
// Ensure older plugin modules that don't declare a `namespace` still build with AGP.
subprojects.forEach { project ->
project.plugins.withId("com.android.library") {
try {
val androidExt = project.extensions.findByName("android") as? LibraryExtension
if (androidExt != null) {
try {
val current = androidExt.namespace
if (current.isNullOrBlank()) {
androidExt.namespace = "com.tasq.${project.name.replace('-', '_')}"
}
} catch (e: Throwable) {
try {
androidExt.namespace = "com.tasq.${project.name.replace('-', '_')}"
} catch (_: Throwable) {}
}
}
} catch (_: Throwable) {}
}
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}