Convert inheritance into delegation

pull/923/head
Simon Marquis 1 year ago
parent 4f8f08380f
commit bc8871a9b0
No known key found for this signature in database
GPG Key ID: AC8D63F7571DC6D6

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

@ -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<Project> {
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<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
@ -32,7 +33,7 @@ abstract class HiltConventionPlugin : Plugin<Project> {
}
dependencies {
"ksp"(libs.findLibrary("hilt.compiler").get())
additionalDependencies(libs)
dependencyHandler(libs)
}
}
}

@ -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<Project> by HiltConventionPlugin(
dependencyHandler = { libs ->
"implementation"(libs.findLibrary("hilt.core").get())
}
}
},
)

Loading…
Cancel
Save