From c58236338c19cca4898d0c686d34fe684970af5f Mon Sep 17 00:00:00 2001 From: Jacob Hagstedt Date: Sun, 18 Oct 2026 23:12:40 +0200 Subject: [PATCH] Android overhaul: one configureAndroidModule for the application and library plugins; coil-compose out of :app AndroidApplicationPlugin and AndroidLibraryPlugin repeated the SDK levels, Java 17, unit-test resources, lint, Kotlin, Robolectric JVM and JUnit set-up; both call configureAndroidModule(CommonExtension) now (the gate's task inputs did not change: every test task stayed up to date). :app imports nothing from coil-compose; it still arrives through :core:design, so the runtime classpaths are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B --- android/app/build.gradle.kts | 1 - .../buildlogic/AndroidApplicationPlugin.kt | 21 +++---------------- .../kvitt/buildlogic/AndroidCommon.kt | 19 +++++++++++++++++ .../kvitt/buildlogic/AndroidLibraryPlugin.kt | 19 ++--------------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 8f015e1..e3f1f5a 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -92,5 +92,4 @@ dependencies { implementation(libs.kotlinx.coroutines.core) implementation(libs.kotlinx.datetime) implementation(libs.coil) - implementation(libs.coil.compose) } diff --git a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidApplicationPlugin.kt b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidApplicationPlugin.kt index 3c011f5..1b64525 100644 --- a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidApplicationPlugin.kt +++ b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidApplicationPlugin.kt @@ -4,31 +4,16 @@ import com.android.build.api.dsl.ApplicationExtension import org.gradle.api.Plugin import org.gradle.api.Project -/** The `:app` module: SDK levels from the catalog, Java 17 bytecode, shared lint rules. */ +/** The `:app` module: [configureAndroidModule] plus the target SDK from the catalog. */ class AndroidApplicationPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("com.android.application") pluginManager.apply("kvitt.architecture") - val catalog = libs extensions.configure(ApplicationExtension::class.java) { - compileSdk = catalog.version("compileSdk").toInt() - defaultConfig { - minSdk = catalog.version("minSdk").toInt() - targetSdk = catalog.version("targetSdk").toInt() - } - compileOptions { - sourceCompatibility = org.gradle.api.JavaVersion.VERSION_17 - targetCompatibility = org.gradle.api.JavaVersion.VERSION_17 - } - testOptions { - unitTests.isIncludeAndroidResources = true - } - lint { kvittLint(this) } + configureAndroidModule(this) + defaultConfig.targetSdk = libs.version("targetSdk").toInt() } - configureKotlinAndroid() - configureRobolectricJvm() - dependencies.add("testImplementation", catalog.library("junit")) } } } diff --git a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidCommon.kt b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidCommon.kt index 970a944..485c9d4 100644 --- a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidCommon.kt +++ b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidCommon.kt @@ -1,11 +1,30 @@ package se.hagstedt.kvitt.buildlogic +import com.android.build.api.dsl.CommonExtension import com.android.build.api.dsl.Lint +import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.tasks.testing.Test import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +/** + * What every Android module shares (application and library): SDK levels from the catalog, Java 17 bytecode, Android + * resources in unit tests (Robolectric), the shared lint rules and JUnit. + */ +internal fun Project.configureAndroidModule(android: CommonExtension) { + val catalog = libs + android.compileSdk = catalog.version("compileSdk").toInt() + android.defaultConfig.minSdk = catalog.version("minSdk").toInt() + android.compileOptions.sourceCompatibility = JavaVersion.VERSION_17 + android.compileOptions.targetCompatibility = JavaVersion.VERSION_17 + android.testOptions.unitTests.isIncludeAndroidResources = true + kvittLint(android.lint) + configureKotlinAndroid() + configureRobolectricJvm() + dependencies.add("testImplementation", catalog.library("junit")) +} + /** * Lint rules shared by every Android module. A string key missing from `values-sv` (or present only there) fails the * build (SPEC AC-19.1). No baseline file: findings are fixed, never silenced (CLAUDE.md › Anti-patterns). diff --git a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidLibraryPlugin.kt b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidLibraryPlugin.kt index bc94fef..cf9376d 100644 --- a/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidLibraryPlugin.kt +++ b/android/build-logic/src/main/kotlin/se/hagstedt/kvitt/buildlogic/AndroidLibraryPlugin.kt @@ -4,32 +4,17 @@ import com.android.build.api.dsl.LibraryExtension import org.gradle.api.Plugin import org.gradle.api.Project -/** Android library module: SDK levels from the catalog, Java 17 bytecode, shared lint rules. */ +/** Android library module: [configureAndroidModule] with the namespace derived from the module path. */ class AndroidLibraryPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("com.android.library") pluginManager.apply("kvitt.architecture") - val catalog = libs extensions.configure(LibraryExtension::class.java) { namespace = kvittNamespace() - compileSdk = catalog.version("compileSdk").toInt() - defaultConfig { - minSdk = catalog.version("minSdk").toInt() - } - compileOptions { - sourceCompatibility = org.gradle.api.JavaVersion.VERSION_17 - targetCompatibility = org.gradle.api.JavaVersion.VERSION_17 - } - testOptions { - unitTests.isIncludeAndroidResources = true - } - lint { kvittLint(this) } + configureAndroidModule(this) } - configureKotlinAndroid() - configureRobolectricJvm() failOnNoTestsOnlyWhenTestsExist() - dependencies.add("testImplementation", catalog.library("junit")) } } }