From fabe8b0b0bfbffc404d6cb77473dc2a5c76942c2 Mon Sep 17 00:00:00 2001 From: Daniel Waiguru Date: Wed, 19 Jun 2024 17:41:18 +0300 Subject: [PATCH] chore: update CommonExtension signature --- .idea/deploymentTargetSelector.xml | 3 -- app/build.gradle.kts | 1 + .../weatherapp/activity/MainActivity.kt | 9 +--- .../weatherapp/convention/AndroidCompose.kt | 17 +++----- .../weatherapp/convention/Jacoco.kt | 9 ++-- .../weatherapp/convention/KotlinAndroid.kt | 32 +++----------- .../weatherapp/convention/KotlinJvm.kt | 43 ++++++++++--------- gradle/libs.versions.toml | 2 +- 8 files changed, 39 insertions(+), 77 deletions(-) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index 3b9a57e..23aa568 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -5,9 +5,6 @@ - - diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 25a4e5a..dbf1749 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -71,6 +71,7 @@ android { dependencies { implementation(project(":presentation")) + implementation(project(":data")) implementation(project(":designsystem")) coreLibraryDesugaring(libs.android.desugarJdkLibs) debugImplementation(libs.leakcanary.android) diff --git a/app/src/main/java/com/danielwaiguru/weatherapp/activity/MainActivity.kt b/app/src/main/java/com/danielwaiguru/weatherapp/activity/MainActivity.kt index 9829ea2..8d6dbce 100644 --- a/app/src/main/java/com/danielwaiguru/weatherapp/activity/MainActivity.kt +++ b/app/src/main/java/com/danielwaiguru/weatherapp/activity/MainActivity.kt @@ -27,22 +27,15 @@ package com.danielwaiguru.weatherapp.activity import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.runtime.CompositionLocalProvider -import androidx.lifecycle.compose.LocalLifecycleOwner import com.danielwaiguru.weatherapp.navigation.WeatherApp import dagger.hilt.android.AndroidEntryPoint -import androidx.compose.ui.platform.LocalLifecycleOwner as PlatformLifecycleOwner @AndroidEntryPoint class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - CompositionLocalProvider( - LocalLifecycleOwner provides PlatformLifecycleOwner.current - ) { - WeatherApp() - } + WeatherApp() } } } diff --git a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/AndroidCompose.kt b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/AndroidCompose.kt index 9c3b26a..400a6a1 100644 --- a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/AndroidCompose.kt +++ b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/AndroidCompose.kt @@ -29,22 +29,18 @@ import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + /** * Configure Compose-specific options */ internal fun Project.configureAndroidCompose( - commonExtension: CommonExtension<*, *, *, *, *>, + commonExtension: CommonExtension<*, *, *, *, *, *>, ) { commonExtension.apply { buildFeatures { compose = true } val libs = extensions.getByType().named("libs") -// composeOptions { -// kotlinCompilerExtensionVersion = libs.findVersion("androidxComposeCompiler").get().toString() -// } packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" @@ -63,10 +59,7 @@ internal fun Project.configureAndroidCompose( add("debugImplementation", libs.findBundle("compose-testing-manifest").get()) } } - - tasks.withType().configureEach { - kotlinOptions { - freeCompilerArgs = freeCompilerArgs - } - } +// extensions.configure { +// enableStrongSkippingMode = true +// } } diff --git a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/Jacoco.kt b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/Jacoco.kt index 1bef416..deb1aef 100644 --- a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/Jacoco.kt +++ b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/Jacoco.kt @@ -40,7 +40,9 @@ private val coverageExclusions = listOf( "**/R.class", "**/R\$*.class", "**/BuildConfig.*", - "**/Manifest*.*" + "**/Manifest*.*", + "**/*_Hilt*.class", + "**/Hilt_*.class", ) private fun String.capitalize() = replaceFirstChar { @@ -85,12 +87,9 @@ internal fun Project.configureJacoco( tasks.withType().configureEach { configure { // Required for JaCoCo + Robolectric - // https://github.com/robolectric/robolectric/issues/2230 - // TODO: Consider removing if not we don't add Robolectric isIncludeNoLocationClasses = true - // Required for JDK 11 with the above - // https://github.com/gradle/gradle/issues/5184#issuecomment-391982009 + // Required for JDK 11 or the above excludes = listOf("jdk.internal.*") } } diff --git a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinAndroid.kt b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinAndroid.kt index cc3449b..e55031b 100644 --- a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinAndroid.kt +++ b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinAndroid.kt @@ -27,17 +27,17 @@ package com.danielwaiguru.weatherapp.convention import com.android.build.api.dsl.CommonExtension +import com.android.build.api.dsl.CompileOptions import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.plugins.ExtensionAware -import org.gradle.kotlin.dsl.provideDelegate -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension /** * Configure base Kotlin with Android options */ internal fun Project.configureKotlinAndroid( - commonExtension: CommonExtension<*, *, *, *, *>, + commonExtension: CommonExtension<*, *, *, *, *, *>, ) { commonExtension.apply { compileSdk = 34 @@ -47,13 +47,6 @@ internal fun Project.configureKotlinAndroid( getByName("release") { isMinifyEnabled = true } - getByName("debug") { - isMinifyEnabled = true - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } } } @@ -63,25 +56,10 @@ internal fun Project.configureKotlinAndroid( isCoreLibraryDesugaringEnabled = true } - kotlinOptions { - // Treat all Kotlin warnings as errors (disabled by default) - // Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties - val warningsAsErrors: String? by project - allWarningsAsErrors = warningsAsErrors.toBoolean() - - freeCompilerArgs = freeCompilerArgs + listOf( - "-opt-in=kotlin.RequiresOptIn", - // Enable experimental coroutines APIs, including Flow - "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", - "-opt-in=kotlinx.coroutines.FlowPreview" - ) - - // Set JVM target to 17 - jvmTarget = JavaVersion.VERSION_17.toString() - } + configureKotlin() } } -fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { +fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: CompileOptions.() -> Unit) { (this as ExtensionAware).extensions.configure("kotlinOptions", block) } \ No newline at end of file diff --git a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinJvm.kt b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinJvm.kt index 6ef69d9..90a99b8 100644 --- a/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinJvm.kt +++ b/build-logic/convention/src/main/java/com/danielwaiguru/weatherapp/convention/KotlinJvm.kt @@ -26,44 +26,45 @@ package com.danielwaiguru.weatherapp.convention 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.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension /** * Configure base Kotlin options for JVM (non-Android) */ internal fun Project.configureKotlinJvm() { extensions.configure { - // Up to Java 17 APIs are available through desugaring + // Up to Java 11 APIs are available through desugaring // https://developer.android.com/studio/write/java11-minimal-support-table sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } - configureKotlin() + configureKotlin() } /** * Configure base Kotlin options */ -private fun Project.configureKotlin() { - // Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947 - tasks.withType().configureEach { - kotlinOptions { - // Set JVM target to 17 - jvmTarget = JavaVersion.VERSION_17.toString() - // Treat all Kotlin warnings as errors (disabled by default) - // Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties - val warningsAsErrors: String? by project - allWarningsAsErrors = warningsAsErrors.toBoolean() - freeCompilerArgs = freeCompilerArgs + listOf( - "-opt-in=kotlin.RequiresOptIn", - // Enable experimental coroutines APIs, including Flow - "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", - "-opt-in=kotlinx.coroutines.FlowPreview", - ) - } +inline fun Project.configureKotlin() = configure { + // 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 -> TODO("Unsupported project extension $this ${T::class}") + }.apply { + jvmTarget = JvmTarget.JVM_17 + allWarningsAsErrors = warningsAsErrors.toBoolean() + freeCompilerArgs.add( + // Enable experimental coroutines APIs, including Flow + "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", + ) } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 568bd24..b84f244 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.5.0" +agp = "8.4.2" kotlin = "2.0.0" ksp = "2.0.0-1.0.22" core-ktx = "1.13.1"