Experiment on implementing Dagger code generation as a compiler plugin
An experiment on the idea of Google's Dagger using different means of code generation: Kotlin compiler.
For now I continue working on implementing richer feature-set. Most of the code is generated in frontend using KotlinPoet. IDE support works out of the box (at least for JB products) thanks to gradle integration. As a side effect of this project, I am exploring how DI can be done better using Kotlin (in compile time safe way).
If you, for any reason, want to look through this:
buildSrc/compiler-plugin/kotlin-plugin
(this is what attaches to compiler)src/main/kotlin
(this is what gets compiled)Right now I have implemented the concept of:
Component
.Module
implemented as object
or class
instance.@Inject
annotated constructor@Inject
annotated fields@Inject
annotated functions (one param only)@Scope
annotations@Factory
@BindsInstance
for components@Qualifier
@Builder
@Binds
Lazy
and Provider
supportTODO (in any order):
Reusable
supportIntoSet
/ IntoMap
Use ./gradlew run
. It will build and install plugin to maven local, after it will compile the test project
using freshly built plugin and run it. Yay!
To get the plugin, follow instructions here.