Files
fast-messenger/build-logic/convention/src/main/kotlin/dev/meloda/fast/KotlinAndroid.kt
T
melod1n 2a238fa1bf Refactor: Upgrade Gradle and streamline build logic
This commit upgrades the project's build system and refactors the build logic for better maintainability and alignment with modern practices.

The Gradle version has been updated from 8.14.2 to 9.3.0, and the Android Gradle Plugin (AGP) has been upgraded to version 9.0.0. This required migrating the build logic to use the new `com.android.build.api.dsl` interfaces instead of the deprecated `com.android.build.gradle` ones.

Key changes:
- Upgraded Gradle to `9.3.0`.
- Upgraded Android Gradle Plugin to `9.0.0`.
- Updated various dependencies including Kotlin, Compose BOM, Chucker, and serialization.
- Removed the explicit `kotlin-android` plugin application, as it's now handled by AGP.
- Migrated build convention plugins to use the new AGP DSL APIs.
- Commented out the custom APK naming logic in `app/build.gradle.kts`.
- Added new `gradle.properties` flags for build configuration.
- Corrected the namespace in `core/model` from `datastore` to `model`.
2026-01-24 14:58:04 +03:00

67 lines
2.5 KiB
Kotlin

package dev.meloda.fast
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.CompileOptions
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension,
) {
when (commonExtension) {
is ApplicationExtension -> commonExtension.compileOptions(buildCompileOptions())
is LibraryExtension -> commonExtension.compileOptions(buildCompileOptions())
}
commonExtension.apply {
compileSdk = 36
}
configureKotlin<KotlinAndroidProjectExtension>()
}
private fun buildCompileOptions(): CompileOptions.() -> Unit = {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
internal fun Project.configureKotlinJvm() {
extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
configureKotlin<KotlinJvmProjectExtension>()
}
private inline fun <reified T : KotlinBaseExtension> Project.configureKotlin() = configure<T> {
// Treat all Kotlin warnings as errors (disabled by default)
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
val warningsAsErrors: String? by project
when (this) {
is KotlinAndroidProjectExtension -> compilerOptions
is KotlinJvmProjectExtension -> compilerOptions
else -> throw IllegalArgumentException("Unsupported project extension $this ${T::class}")
}.apply {
jvmTarget = JvmTarget.JVM_21
allWarningsAsErrors = warningsAsErrors.toBoolean()
freeCompilerArgs.addAll(
"-opt-in=kotlin.RequiresOptIn",
// Enable experimental coroutines APIs, including Flow
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-Xannotation-default-target=param-property",
)
}
}