square / anvil

A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Apache License 2.0
1.29k stars 76 forks source link

Auto wire KSP when running in KSP mode #901

Closed ZacSweers closed 4 months ago

ZacSweers commented 4 months ago

This propagates values from AnvilExtension to KSP args automatically when KSP mode is enabled, easing use in projects. Otherwise, KSP processors end up being inert since they require reading an AnvilContext from these args. This also automatically adds the Anvil compiler to the corresponding KSP configuration.

Most of this logic is adapted from what's been working well in Moshi-IR's plugin: https://github.com/ZacSweers/MoshiX/blob/main/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt#L30-L69