android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
15.92k stars 2.81k forks source link

Syntax improvements in Convention Plugins #1504

Closed Javernaut closed 2 weeks ago

Javernaut commented 2 weeks ago

What I have done and why

Ultimately, the goal was to refactor this:

class AndroidHiltConventionPlugin : Plugin<Project> {
    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())
            }

        }
    }
}

into this:

class AndroidHiltConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply(libs.plugins.ksp)
                apply(libs.plugins.hilt)
            }

            dependencies {
                implementation(libs.hilt.android)
                ksp(libs.hilt.compiler)
            }
        }
    }
}

No behavioral changes. Purely syntactic polishing.

SimonMarquis commented 2 weeks ago

Hi @Javernaut and thanks for the PR, unfortunately this solution has already been discussed in this repository:

Thanks for the proposal! Closing at the moment as this is a workaround that we probably don't want to recommend broadly, and could be brittle with different versions of Gradle. Once Gradle has full support this would be great to add! https://github.com/android/nowinandroid/pull/318#issuecomment-1270143404