From 4f8f08380fb3ba26199f3324b98c37d2d005876a Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 22 Dec 2023 14:21:00 +0100 Subject: [PATCH 1/6] Prep work for JVM alternatives to modules/plugins --- build-logic/convention/build.gradle.kts | 4 ++ .../kotlin/AndroidHiltConventionPlugin.kt | 27 ++++--------- .../src/main/kotlin/HiltConventionPlugin.kt | 39 +++++++++++++++++++ .../main/kotlin/JvmHiltConventionPlugin.kt | 24 ++++++++++++ core/datastore/build.gradle.kts | 2 +- gradle/libs.versions.toml | 6 ++- 6 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt create mode 100644 build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index aa0e615ad..cf351846e 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -110,5 +110,9 @@ gradlePlugin { id = "nowinandroid.jvm.library" implementationClass = "JvmLibraryConventionPlugin" } + register("jvmHilt") { + id = "nowinandroid.jvm.hilt" + implementationClass = "JvmHiltConventionPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt index fcb4f823e..c4fd1b3d0 100644 --- a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt @@ -14,25 +14,14 @@ * limitations under the License. */ -import com.google.samples.apps.nowinandroid.libs -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.dependencies +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.kotlin.dsl.DependencyHandlerScope -class AndroidHiltConventionPlugin : Plugin { - override fun apply(target: Project) { - with(target) { - with(pluginManager) { - apply("com.google.devtools.ksp") - apply("dagger.hilt.android.plugin") - } - - dependencies { - "implementation"(libs.findLibrary("hilt.android").get()) - "ksp"(libs.findLibrary("hilt.compiler").get()) - } - - } +class AndroidHiltConventionPlugin : HiltConventionPlugin() { + override val basePluginId = "dagger.hilt.android.plugin" + override fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) { + "implementation"(libs.findLibrary("hilt.android").get()) + "kspAndroidTest"(libs.findLibrary("hilt.compiler").get()) + "kspTest"(libs.findLibrary("hilt.compiler").get()) } - } diff --git a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt new file mode 100644 index 000000000..1a596d87f --- /dev/null +++ b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.google.samples.apps.nowinandroid.libs +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.kotlin.dsl.DependencyHandlerScope +import org.gradle.kotlin.dsl.dependencies + +abstract class HiltConventionPlugin : Plugin { + open val basePluginId: String? = null + protected abstract fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) + override fun apply(target: Project) { + with(target) { + with(pluginManager) { + basePluginId?.let(::apply) + apply("com.google.devtools.ksp") + } + dependencies { + "ksp"(libs.findLibrary("hilt.compiler").get()) + additionalDependencies(libs) + } + } + } +} diff --git a/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt new file mode 100644 index 000000000..be4c9a61d --- /dev/null +++ b/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.kotlin.dsl.DependencyHandlerScope + +class JvmHiltConventionPlugin : HiltConventionPlugin() { + override fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) { + "implementation"(libs.findLibrary("hilt.core").get()) + } +} \ No newline at end of file diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 34ea5ee78..725396ac4 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -33,7 +33,7 @@ android { } dependencies { - api(libs.androidx.dataStore.core) + api(libs.androidx.dataStore) api(projects.core.datastoreProto) api(projects.core.model) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 795510bce..9a1e92e84 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -79,7 +79,8 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" } androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "androidxCoreSplashscreen" } -androidx-dataStore-core = { group = "androidx.datastore", name = "datastore", version.ref = "androidxDataStore" } +androidx-dataStore = { group = "androidx.datastore", name = "datastore", version.ref = "androidxDataStore" } +androidx-dataStore-core = { group = "androidx.datastore", name = "datastore-core", version.ref = "androidxDataStore" } androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" } androidx-lifecycle-runtimeCompose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidxLifecycle" } androidx-lifecycle-viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } @@ -109,10 +110,13 @@ google-oss-licenses-plugin = { group = "com.google.android.gms", name = "oss-lic hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" } hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" } +hilt-core = { group = "com.google.dagger", name = "hilt-core", version.ref = "hilt" } hilt-ext-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltExt" } hilt-ext-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hiltExt" } javax-inject = { module = "javax.inject:javax.inject", version = "1" } kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" } +kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" } +kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" } kotlinx-coroutines-guava = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-guava", version.ref = "kotlinxCoroutines" } kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" } kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinxDatetime" } From bc8871a9b0dbd3da50e0ec05f58d42272423e846 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 3 Sep 2023 13:00:02 +0200 Subject: [PATCH 2/6] Convert inheritance into delegation --- .../src/main/kotlin/AndroidHiltConventionPlugin.kt | 13 +++++++------ .../src/main/kotlin/HiltConventionPlugin.kt | 9 +++++---- .../src/main/kotlin/JvmHiltConventionPlugin.kt | 12 ++++++------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt index c4fd1b3d0..32be84dbb 100644 --- a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt @@ -14,14 +14,15 @@ * limitations under the License. */ -import org.gradle.api.artifacts.VersionCatalog -import org.gradle.kotlin.dsl.DependencyHandlerScope +import org.gradle.api.Plugin +import org.gradle.api.Project -class AndroidHiltConventionPlugin : HiltConventionPlugin() { - override val basePluginId = "dagger.hilt.android.plugin" - override fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) { +class AndroidHiltConventionPlugin : Plugin by HiltConventionPlugin( + basePluginId = "dagger.hilt.android.plugin", + dependencyHandler = { libs -> "implementation"(libs.findLibrary("hilt.android").get()) + "ksp"(libs.findLibrary("hilt.compiler").get()) "kspAndroidTest"(libs.findLibrary("hilt.compiler").get()) "kspTest"(libs.findLibrary("hilt.compiler").get()) } -} +) diff --git a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt index 1a596d87f..51d963ac6 100644 --- a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt @@ -21,9 +21,10 @@ import org.gradle.api.artifacts.VersionCatalog import org.gradle.kotlin.dsl.DependencyHandlerScope import org.gradle.kotlin.dsl.dependencies -abstract class HiltConventionPlugin : Plugin { - open val basePluginId: String? = null - protected abstract fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) +class HiltConventionPlugin( + val basePluginId: String? = null, + val dependencyHandler: DependencyHandlerScope.(libs: VersionCatalog) -> Unit +) : Plugin { override fun apply(target: Project) { with(target) { with(pluginManager) { @@ -32,7 +33,7 @@ abstract class HiltConventionPlugin : Plugin { } dependencies { "ksp"(libs.findLibrary("hilt.compiler").get()) - additionalDependencies(libs) + dependencyHandler(libs) } } } diff --git a/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt index be4c9a61d..dce0aecef 100644 --- a/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt @@ -14,11 +14,11 @@ * limitations under the License. */ -import org.gradle.api.artifacts.VersionCatalog -import org.gradle.kotlin.dsl.DependencyHandlerScope +import org.gradle.api.Plugin +import org.gradle.api.Project -class JvmHiltConventionPlugin : HiltConventionPlugin() { - override fun DependencyHandlerScope.additionalDependencies(libs: VersionCatalog) { +class JvmHiltConventionPlugin : Plugin by HiltConventionPlugin( + dependencyHandler = { libs -> "implementation"(libs.findLibrary("hilt.core").get()) - } -} \ No newline at end of file + }, +) From 4dd51cb6b146aeedbd086c2a9001734ff10d8870 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 22 Dec 2023 14:21:47 +0100 Subject: [PATCH 3/6] Merge common dependencies --- .../convention/src/main/kotlin/AndroidHiltConventionPlugin.kt | 2 -- build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt index 32be84dbb..3fa416536 100644 --- a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt @@ -21,8 +21,6 @@ class AndroidHiltConventionPlugin : Plugin by HiltConventionPlugin( basePluginId = "dagger.hilt.android.plugin", dependencyHandler = { libs -> "implementation"(libs.findLibrary("hilt.android").get()) - "ksp"(libs.findLibrary("hilt.compiler").get()) "kspAndroidTest"(libs.findLibrary("hilt.compiler").get()) - "kspTest"(libs.findLibrary("hilt.compiler").get()) } ) diff --git a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt index 51d963ac6..952386fd6 100644 --- a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt @@ -33,6 +33,7 @@ class HiltConventionPlugin( } dependencies { "ksp"(libs.findLibrary("hilt.compiler").get()) + "kspTest"(libs.findLibrary("hilt.compiler").get()) dependencyHandler(libs) } } From 45743175fb1897ff32da0a7c8f21e29771e09fe9 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 22 Dec 2023 14:27:14 +0100 Subject: [PATCH 4/6] Reference `nowinandroid-jvm-hilt` plugin in versions catalog --- gradle/libs.versions.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9a1e92e84..1a8d82dce 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -181,3 +181,4 @@ nowinandroid-android-lint = { id = "nowinandroid.android.lint", version = "unspe nowinandroid-android-room = { id = "nowinandroid.android.room", version = "unspecified" } nowinandroid-android-test = { id = "nowinandroid.android.test", version = "unspecified" } nowinandroid-jvm-library = { id = "nowinandroid.jvm.library", version = "unspecified" } +nowinandroid-jvm-hilt = { id = "nowinandroid.jvm.hilt", version = "unspecified" } From 61c7d71870bc20393cbc0984068dac77e7b9d723 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 22 Dec 2023 14:40:30 +0100 Subject: [PATCH 5/6] Migrate `:core:common` to pure JVM module The notification icons are now stored in `:core:notifications`. This forces `:sync:work` to depend on it. Another solution could be to provide the resource id through Hilt, but it would require more changes. --- core/common/build.gradle.kts | 10 +++------- core/common/src/main/AndroidManifest.xml | 17 ----------------- core/notifications/build.gradle.kts | 1 - .../core/notifications/SystemTrayNotifier.kt | 8 ++------ ...core_notifications_ic_nia_notification.xml} | 0 ...core_notifications_ic_nia_notification.png} | Bin ...core_notifications_ic_nia_notification.png} | Bin ...core_notifications_ic_nia_notification.png} | Bin ...core_notifications_ic_nia_notification.png} | Bin sync/work/build.gradle.kts | 1 + .../sync/initializers/SyncWorkHelpers.kt | 2 +- 11 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 core/common/src/main/AndroidManifest.xml rename core/{common/src/main/res/drawable-anydpi-v24/core_common_ic_nia_notification.xml => notifications/src/main/res/drawable-anydpi-v24/core_notifications_ic_nia_notification.xml} (100%) rename core/{common/src/main/res/drawable-hdpi/core_common_ic_nia_notification.png => notifications/src/main/res/drawable-hdpi/core_notifications_ic_nia_notification.png} (100%) rename core/{common/src/main/res/drawable-mdpi/core_common_ic_nia_notification.png => notifications/src/main/res/drawable-mdpi/core_notifications_ic_nia_notification.png} (100%) rename core/{common/src/main/res/drawable-xhdpi/core_common_ic_nia_notification.png => notifications/src/main/res/drawable-xhdpi/core_notifications_ic_nia_notification.png} (100%) rename core/{common/src/main/res/drawable-xxhdpi/core_common_ic_nia_notification.png => notifications/src/main/res/drawable-xxhdpi/core_notifications_ic_nia_notification.png} (100%) diff --git a/core/common/build.gradle.kts b/core/common/build.gradle.kts index 51ae627dc..94dd3c09e 100644 --- a/core/common/build.gradle.kts +++ b/core/common/build.gradle.kts @@ -14,16 +14,12 @@ * limitations under the License. */ plugins { - alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) -} - -android { - namespace = "com.google.samples.apps.nowinandroid.core.common" + alias(libs.plugins.nowinandroid.jvm.library) + alias(libs.plugins.nowinandroid.jvm.hilt) } dependencies { + implementation(libs.kotlinx.coroutines.core) testImplementation(libs.kotlinx.coroutines.test) testImplementation(libs.turbine) } \ No newline at end of file diff --git a/core/common/src/main/AndroidManifest.xml b/core/common/src/main/AndroidManifest.xml deleted file mode 100644 index 51d0cfc2e..000000000 --- a/core/common/src/main/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - \ No newline at end of file diff --git a/core/notifications/build.gradle.kts b/core/notifications/build.gradle.kts index 92871b72b..7b0f14fc8 100644 --- a/core/notifications/build.gradle.kts +++ b/core/notifications/build.gradle.kts @@ -28,5 +28,4 @@ dependencies { implementation(projects.core.common) compileOnly(platform(libs.androidx.compose.bom)) - compileOnly(libs.androidx.compose.runtime) } diff --git a/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt b/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt index ebad9fda3..38d905ad1 100644 --- a/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt +++ b/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt @@ -71,9 +71,7 @@ internal class SystemTrayNotifier @Inject constructor( val newsNotifications = truncatedNewsResources .map { newsResource -> createNewsNotification { - setSmallIcon( - com.google.samples.apps.nowinandroid.core.common.R.drawable.core_common_ic_nia_notification, - ) + setSmallIcon(R.drawable.core_notifications_ic_nia_notification) .setContentTitle(newsResource.title) .setContentText(newsResource.content) .setContentIntent(newsPendingIntent(newsResource)) @@ -88,9 +86,7 @@ internal class SystemTrayNotifier @Inject constructor( ) setContentTitle(title) .setContentText(title) - .setSmallIcon( - com.google.samples.apps.nowinandroid.core.common.R.drawable.core_common_ic_nia_notification, - ) + .setSmallIcon(R.drawable.core_notifications_ic_nia_notification) // Build summary info into InboxStyle template. .setStyle(newsNotificationStyle(truncatedNewsResources, title)) .setGroup(NEWS_NOTIFICATION_GROUP) diff --git a/core/common/src/main/res/drawable-anydpi-v24/core_common_ic_nia_notification.xml b/core/notifications/src/main/res/drawable-anydpi-v24/core_notifications_ic_nia_notification.xml similarity index 100% rename from core/common/src/main/res/drawable-anydpi-v24/core_common_ic_nia_notification.xml rename to core/notifications/src/main/res/drawable-anydpi-v24/core_notifications_ic_nia_notification.xml diff --git a/core/common/src/main/res/drawable-hdpi/core_common_ic_nia_notification.png b/core/notifications/src/main/res/drawable-hdpi/core_notifications_ic_nia_notification.png similarity index 100% rename from core/common/src/main/res/drawable-hdpi/core_common_ic_nia_notification.png rename to core/notifications/src/main/res/drawable-hdpi/core_notifications_ic_nia_notification.png diff --git a/core/common/src/main/res/drawable-mdpi/core_common_ic_nia_notification.png b/core/notifications/src/main/res/drawable-mdpi/core_notifications_ic_nia_notification.png similarity index 100% rename from core/common/src/main/res/drawable-mdpi/core_common_ic_nia_notification.png rename to core/notifications/src/main/res/drawable-mdpi/core_notifications_ic_nia_notification.png diff --git a/core/common/src/main/res/drawable-xhdpi/core_common_ic_nia_notification.png b/core/notifications/src/main/res/drawable-xhdpi/core_notifications_ic_nia_notification.png similarity index 100% rename from core/common/src/main/res/drawable-xhdpi/core_common_ic_nia_notification.png rename to core/notifications/src/main/res/drawable-xhdpi/core_notifications_ic_nia_notification.png diff --git a/core/common/src/main/res/drawable-xxhdpi/core_common_ic_nia_notification.png b/core/notifications/src/main/res/drawable-xxhdpi/core_notifications_ic_nia_notification.png similarity index 100% rename from core/common/src/main/res/drawable-xxhdpi/core_common_ic_nia_notification.png rename to core/notifications/src/main/res/drawable-xxhdpi/core_notifications_ic_nia_notification.png diff --git a/sync/work/build.gradle.kts b/sync/work/build.gradle.kts index 7e61c7389..1bcc15964 100644 --- a/sync/work/build.gradle.kts +++ b/sync/work/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { implementation(libs.hilt.ext.work) implementation(projects.core.analytics) implementation(projects.core.data) + implementation(projects.core.notifications) prodImplementation(libs.firebase.cloud.messaging) prodImplementation(platform(libs.firebase.bom)) diff --git a/sync/work/src/main/kotlin/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt b/sync/work/src/main/kotlin/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt index 843510aaf..6c4a29373 100644 --- a/sync/work/src/main/kotlin/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt +++ b/sync/work/src/main/kotlin/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt @@ -71,7 +71,7 @@ private fun Context.syncWorkNotification(): Notification { SYNC_NOTIFICATION_CHANNEL_ID, ) .setSmallIcon( - com.google.samples.apps.nowinandroid.core.common.R.drawable.core_common_ic_nia_notification, + com.google.samples.apps.nowinandroid.core.notifications.R.drawable.core_notifications_ic_nia_notification, ) .setContentTitle(getString(R.string.sync_work_notification_title)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) From d56e06e67643db0f894686a26fa85fd422a587c3 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 5 Jul 2024 21:23:53 +0200 Subject: [PATCH 6/6] Merge Android & JVM plugins into a single `HiltConventionPlugin` --- app/build.gradle.kts | 2 +- build-logic/convention/build.gradle.kts | 10 +++---- .../kotlin/AndroidFeatureConventionPlugin.kt | 2 +- .../kotlin/AndroidHiltConventionPlugin.kt | 26 ------------------- .../src/main/kotlin/HiltConventionPlugin.kt | 26 +++++++++---------- .../main/kotlin/JvmHiltConventionPlugin.kt | 24 ----------------- core/analytics/build.gradle.kts | 2 +- core/common/build.gradle.kts | 2 +- core/data-test/build.gradle.kts | 2 +- core/data/build.gradle.kts | 2 +- core/database/build.gradle.kts | 2 +- core/datastore-test/build.gradle.kts | 2 +- core/datastore/build.gradle.kts | 2 +- core/network/build.gradle.kts | 2 +- core/notifications/build.gradle.kts | 2 +- core/screenshot-testing/build.gradle.kts | 2 +- core/testing/build.gradle.kts | 2 +- gradle/libs.versions.toml | 5 ++-- sync/sync-test/build.gradle.kts | 2 +- sync/work/build.gradle.kts | 2 +- ui-test-hilt-manifest/build.gradle.kts | 2 +- 21 files changed, 34 insertions(+), 89 deletions(-) delete mode 100644 build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt delete mode 100644 build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 47b8af943..9c6989f67 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,8 +20,8 @@ plugins { alias(libs.plugins.nowinandroid.android.application.compose) alias(libs.plugins.nowinandroid.android.application.flavors) alias(libs.plugins.nowinandroid.android.application.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) alias(libs.plugins.nowinandroid.android.application.firebase) + alias(libs.plugins.nowinandroid.hilt) id("com.google.android.gms.oss-licenses-plugin") alias(libs.plugins.baselineprofile) alias(libs.plugins.roborazzi) diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 27956195f..c735fa4a0 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -89,9 +89,9 @@ gradlePlugin { id = "nowinandroid.android.test" implementationClass = "AndroidTestConventionPlugin" } - register("androidHilt") { - id = "nowinandroid.android.hilt" - implementationClass = "AndroidHiltConventionPlugin" + register("hilt") { + id = "nowinandroid.hilt" + implementationClass = "HiltConventionPlugin" } register("androidRoom") { id = "nowinandroid.android.room" @@ -113,9 +113,5 @@ gradlePlugin { id = "nowinandroid.jvm.library" implementationClass = "JvmLibraryConventionPlugin" } - register("jvmHilt") { - id = "nowinandroid.jvm.hilt" - implementationClass = "JvmHiltConventionPlugin" - } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt index 024ec4fe0..9110e7fa3 100644 --- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt @@ -27,7 +27,7 @@ class AndroidFeatureConventionPlugin : Plugin { with(target) { pluginManager.apply { apply("nowinandroid.android.library") - apply("nowinandroid.android.hilt") + apply("nowinandroid.hilt") } extensions.configure { testOptions.animationsDisabled = true diff --git a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt deleted file mode 100644 index 3fa416536..000000000 --- a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class AndroidHiltConventionPlugin : Plugin by HiltConventionPlugin( - basePluginId = "dagger.hilt.android.plugin", - dependencyHandler = { libs -> - "implementation"(libs.findLibrary("hilt.android").get()) - "kspAndroidTest"(libs.findLibrary("hilt.compiler").get()) - } -) diff --git a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt index 952386fd6..a8228e5af 100644 --- a/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt @@ -14,27 +14,27 @@ * limitations under the License. */ +import com.android.build.gradle.api.AndroidBasePlugin import com.google.samples.apps.nowinandroid.libs import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.artifacts.VersionCatalog -import org.gradle.kotlin.dsl.DependencyHandlerScope import org.gradle.kotlin.dsl.dependencies -class HiltConventionPlugin( - val basePluginId: String? = null, - val dependencyHandler: DependencyHandlerScope.(libs: VersionCatalog) -> Unit -) : Plugin { +class HiltConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { - with(pluginManager) { - basePluginId?.let(::apply) - apply("com.google.devtools.ksp") - } + pluginManager.apply("com.google.devtools.ksp") dependencies { - "ksp"(libs.findLibrary("hilt.compiler").get()) - "kspTest"(libs.findLibrary("hilt.compiler").get()) - dependencyHandler(libs) + add("ksp", libs.findLibrary("hilt.compiler").get()) + add("implementation", libs.findLibrary("hilt.core").get()) + } + + /** Add support for Android modules, based on [AndroidBasePlugin] */ + pluginManager.withPlugin("com.android.base") { + pluginManager.apply("dagger.hilt.android.plugin") + dependencies { + add("implementation", libs.findLibrary("hilt.android").get()) + } } } } diff --git a/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt deleted file mode 100644 index dce0aecef..000000000 --- a/build-logic/convention/src/main/kotlin/JvmHiltConventionPlugin.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class JvmHiltConventionPlugin : Plugin by HiltConventionPlugin( - dependencyHandler = { libs -> - "implementation"(libs.findLibrary("hilt.core").get()) - }, -) diff --git a/core/analytics/build.gradle.kts b/core/analytics/build.gradle.kts index 023574e6f..72f7620b0 100644 --- a/core/analytics/build.gradle.kts +++ b/core/analytics/build.gradle.kts @@ -16,7 +16,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.compose) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/common/build.gradle.kts b/core/common/build.gradle.kts index 94dd3c09e..f1aa9771c 100644 --- a/core/common/build.gradle.kts +++ b/core/common/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.jvm.library) - alias(libs.plugins.nowinandroid.jvm.hilt) + alias(libs.plugins.nowinandroid.hilt) } dependencies { diff --git a/core/data-test/build.gradle.kts b/core/data-test/build.gradle.kts index b166df288..420c34a57 100644 --- a/core/data-test/build.gradle.kts +++ b/core/data-test/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index 142637ff9..83c268aab 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -16,7 +16,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) id("kotlinx-serialization") } diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index a9e38ead7..8bab355b4 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -17,8 +17,8 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) alias(libs.plugins.nowinandroid.android.room) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/datastore-test/build.gradle.kts b/core/datastore-test/build.gradle.kts index 53e5e2c0c..375b1d3d8 100644 --- a/core/datastore-test/build.gradle.kts +++ b/core/datastore-test/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 725396ac4..b17bf6abd 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -17,7 +17,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 689a99e73..d12482a56 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -17,7 +17,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) id("kotlinx-serialization") id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") } diff --git a/core/notifications/build.gradle.kts b/core/notifications/build.gradle.kts index 7b0f14fc8..34393049b 100644 --- a/core/notifications/build.gradle.kts +++ b/core/notifications/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/screenshot-testing/build.gradle.kts b/core/screenshot-testing/build.gradle.kts index 1b816fc67..794416ba9 100644 --- a/core/screenshot-testing/build.gradle.kts +++ b/core/screenshot-testing/build.gradle.kts @@ -16,7 +16,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.compose) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/core/testing/build.gradle.kts b/core/testing/build.gradle.kts index 90f2405a4..01696d5e8 100644 --- a/core/testing/build.gradle.kts +++ b/core/testing/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 52ec568c9..cc44b5003 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -122,7 +122,7 @@ google-oss-licenses = { group = "com.google.android.gms", name = "play-services- google-oss-licenses-plugin = { group = "com.google.android.gms", name = "oss-licenses-plugin", version.ref = "googleOssPlugin" } hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" } -hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" } +hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" } hilt-core = { group = "com.google.dagger", name = "hilt-core", version.ref = "hilt" } hilt-ext-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltExt" } hilt-ext-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hiltExt" } @@ -187,12 +187,11 @@ nowinandroid-android-application-firebase = { id = "nowinandroid.android.applica nowinandroid-android-application-flavors = { id = "nowinandroid.android.application.flavors", version = "unspecified" } nowinandroid-android-application-jacoco = { id = "nowinandroid.android.application.jacoco", version = "unspecified" } nowinandroid-android-feature = { id = "nowinandroid.android.feature", version = "unspecified" } -nowinandroid-android-hilt = { id = "nowinandroid.android.hilt", version = "unspecified" } nowinandroid-android-library = { id = "nowinandroid.android.library", version = "unspecified" } nowinandroid-android-library-compose = { id = "nowinandroid.android.library.compose", version = "unspecified" } nowinandroid-android-library-jacoco = { id = "nowinandroid.android.library.jacoco", version = "unspecified" } nowinandroid-android-lint = { id = "nowinandroid.android.lint", version = "unspecified" } nowinandroid-android-room = { id = "nowinandroid.android.room", version = "unspecified" } nowinandroid-android-test = { id = "nowinandroid.android.test", version = "unspecified" } +nowinandroid-hilt = { id = "nowinandroid.hilt", version = "unspecified" } nowinandroid-jvm-library = { id = "nowinandroid.jvm.library", version = "unspecified" } -nowinandroid-jvm-hilt = { id = "nowinandroid.jvm.hilt", version = "unspecified" } diff --git a/sync/sync-test/build.gradle.kts b/sync/sync-test/build.gradle.kts index 0fac2cf83..fd9af1882 100644 --- a/sync/sync-test/build.gradle.kts +++ b/sync/sync-test/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/sync/work/build.gradle.kts b/sync/work/build.gradle.kts index 1bcc15964..7b4b55a18 100644 --- a/sync/work/build.gradle.kts +++ b/sync/work/build.gradle.kts @@ -16,7 +16,7 @@ plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android { diff --git a/ui-test-hilt-manifest/build.gradle.kts b/ui-test-hilt-manifest/build.gradle.kts index f41482814..3f084c6df 100644 --- a/ui-test-hilt-manifest/build.gradle.kts +++ b/ui-test-hilt-manifest/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { alias(libs.plugins.nowinandroid.android.library) - alias(libs.plugins.nowinandroid.android.hilt) + alias(libs.plugins.nowinandroid.hilt) } android {