Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Merge Android & JVM plugins into a single `HiltConventionPlugin`

Simon Marquisd56e06e67643
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<Project> {
with(target) {
pluginManager.apply {
apply("nowinandroid.android.library")
- apply("nowinandroid.android.hilt")
+ apply("nowinandroid.hilt")
}
extensions.configure<LibraryExtension> {
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<Project> 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<Project> {
+class HiltConventionPlugin : Plugin<Project> {
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<Project> 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 {