From aa12480984228c0b8b3c9973f0c3f7df39c66a1d Mon Sep 17 00:00:00 2001 From: Raghav Aggarwal Date: Sat, 10 Jun 2023 15:57:37 +0530 Subject: [PATCH 1/2] add Custom Gradle Plugin for configuring Hilt in different modules --- app/build.gradle | 10 ++++------ buildSrc/build.gradle.kts | 17 +++++++++++++++++ buildSrc/src/main/java/HiltPlugin.kt | 11 +++++++++++ data/build.gradle | 6 +----- 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/java/HiltPlugin.kt diff --git a/app/build.gradle b/app/build.gradle index c89edcd..3f07c63 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ plugins { id "org.jlleitschuh.gradle.ktlint" // Hilt doesn't supports KSP yet id 'kotlin-kapt' - id 'com.google.dagger.hilt.android' + id 'com.raghav.hiltplugin' } android { @@ -84,11 +84,8 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:$okhttp_interceptor" implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_interceptor" - // Hilt - def hilt_version = "2.44" + // To Create ViewModel Instance when Hilt is used along with Compose Navigation def hilt_navigation_compose = "1.0.0" - implementation "com.google.dagger:hilt-android:$hilt_version" - kapt "com.google.dagger:hilt-compiler:$hilt_version" implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose" // Testing coroutines @@ -107,4 +104,5 @@ dependencies { kapt { correctErrorTypes true -} \ No newline at end of file +} + diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..e8e88e4 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} + +gradlePlugin { + plugins { + create("HiltPlugin") { + id = "com.raghav.hiltplugin" + implementationClass = "HiltPlugin" + version = "1.0.0" + } + } +} diff --git a/buildSrc/src/main/java/HiltPlugin.kt b/buildSrc/src/main/java/HiltPlugin.kt new file mode 100644 index 0000000..12c7a71 --- /dev/null +++ b/buildSrc/src/main/java/HiltPlugin.kt @@ -0,0 +1,11 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project + +class HiltPlugin : Plugin { + + override fun apply(target: Project) { + target.plugins.apply("com.google.dagger.hilt.android") + target.dependencies.add("implementation", "com.google.dagger:hilt-android:2.44") + target.dependencies.add("kapt", "com.google.dagger:hilt-compiler:2.44") + } +} diff --git a/data/build.gradle b/data/build.gradle index 672b7a4..3eb90d8 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -4,7 +4,7 @@ plugins { id "org.jlleitschuh.gradle.ktlint" // Hilt doesn't supports KSP yet id 'kotlin-kapt' - id 'com.google.dagger.hilt.android' + id 'com.raghav.hiltplugin' } android { @@ -49,10 +49,6 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2" implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2" - - // Hilt - implementation "com.google.dagger:hilt-android:2.44" - kapt "com.google.dagger:hilt-compiler:2.44" } kapt { From dea6d4e770697245bf38a2d2afeab60096cb2d12 Mon Sep 17 00:00:00 2001 From: Raghav Aggarwal Date: Tue, 19 Sep 2023 16:29:34 +0530 Subject: [PATCH 2/2] resolve merge conflicts and fixes --- app/build.gradle | 8 -------- buildSrc/src/main/java/HiltPlugin.kt | 5 +++-- data/build.gradle | 12 ------------ 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 19cb617..86fb255 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,8 +3,6 @@ plugins { id 'org.jetbrains.kotlin.android' id "org.jlleitschuh.gradle.ktlint" // Hilt doesn't supports KSP yet - id 'kotlin-kapt' - id 'com.google.dagger.hilt.android' id("com.google.devtools.ksp") id 'com.raghav.hiltplugin' } @@ -102,8 +100,6 @@ dependencies { implementation("com.squareup.retrofit2:converter-moshi:$retrofit_version") implementation "com.squareup.okhttp3:okhttp:$okhttp_version" - // Hilt - def hilt_version = "2.44" def hilt_navigation_compose = "1.0.0" implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose" @@ -134,7 +130,3 @@ dependencies { androidTestImplementation "com.google.truth:truth:1.1.4" } - -kapt { - correctErrorTypes true -} \ No newline at end of file diff --git a/buildSrc/src/main/java/HiltPlugin.kt b/buildSrc/src/main/java/HiltPlugin.kt index 12c7a71..6f51c26 100644 --- a/buildSrc/src/main/java/HiltPlugin.kt +++ b/buildSrc/src/main/java/HiltPlugin.kt @@ -5,7 +5,8 @@ class HiltPlugin : Plugin { override fun apply(target: Project) { target.plugins.apply("com.google.dagger.hilt.android") - target.dependencies.add("implementation", "com.google.dagger:hilt-android:2.44") - target.dependencies.add("kapt", "com.google.dagger:hilt-compiler:2.44") + target.plugins.apply("kotlin-kapt") + target.dependencies.add("implementation", "com.google.dagger:hilt-android:2.47") + target.dependencies.add("kapt", "com.google.dagger:hilt-compiler:2.47") } } diff --git a/data/build.gradle b/data/build.gradle index 245f0ea..c5abe8b 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -3,10 +3,6 @@ plugins { id 'org.jetbrains.kotlin.android' id "org.jlleitschuh.gradle.ktlint" id("com.google.devtools.ksp") - id "kotlin-kapt" - id 'com.google.dagger.hilt.android' - // Hilt doesn't supports KSP yet - id 'kotlin-kapt' id 'com.raghav.hiltplugin' } @@ -70,10 +66,6 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2" implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2" - // Hilt - implementation "com.google.dagger:hilt-android:2.47" - kapt "com.google.dagger:hilt-compiler:2.47" - // Room implementation "androidx.room:room-runtime:2.5.1" ksp "androidx.room:room-compiler:2.5.1" @@ -94,7 +86,3 @@ dependencies { androidTestImplementation "androidx.arch.core:core-testing:2.1.0" } - -kapt { - correctErrorTypes true -} \ No newline at end of file