Merge Android & JVM plugins into a single `HiltConventionPlugin`

pull/923/head
Simon Marquis 5 months ago
parent e71ce1fc00
commit d56e06e676

@ -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)

@ -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"
}
}
}

@ -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

@ -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())
}
)

@ -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 {
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 {
"ksp"(libs.findLibrary("hilt.compiler").get())
"kspTest"(libs.findLibrary("hilt.compiler").get())
dependencyHandler(libs)
add("implementation", libs.findLibrary("hilt.android").get())
}
}
}
}

@ -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())
},
)

@ -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 {

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.jvm.library)
alias(libs.plugins.nowinandroid.jvm.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
dependencies {

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

@ -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")
}

@ -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 {

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

@ -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 {

@ -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")
}

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

@ -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 {

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

@ -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" }

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

@ -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 {

@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.hilt)
}
android {

Loading…
Cancel
Save