Koin Compiler Plugin - Documentation
Central documentation hub for debugging, developing, and understanding the Koin Compiler Plugin.
koin-compiler-plugin/
├── koin-compiler-plugin/ # FIR + IR compiler plugin
├── koin-compiler-gradle-plugin/ # Gradle integration
└── test-apps/ # Test samples
Note: The plugin support library (stub + target functions) is part of the main Koin repository (koin-annotations).
# Build and publish plugin locally
./install.sh
# Run sample tests
cd test-apps && ./gradlew :sample-app:jvmTest
# View plugin logs during compilation (both FIR and IR)
cd test-apps && ./gradlew :sample-app:compileKotlinJvm 2>&1 | grep " \[Koin-Plugin"
# Enable debug logging in build.gradle.kts: koinCompiler { debugLogs = true }
File
Phase
Purpose
fir/KoinModuleFirGenerator.kt
FIR
Generates .module property + hints
ir/KoinAnnotationProcessor.kt
IR-1
Processes @Singleton/@Factory (classes, module functions, top-level functions)
ir/KoinDSLTransformer.kt
IR-2
Transforms single<T>()
ir/KoinStartTransformer.kt
IR-3
Transforms startKoin<T>()
KoinConfigurationRegistry.kt
FIR→IR
Cross-phase communication
Plugin Support (Stubs + Targets) — Included in Koin
File
Purpose
BaseDSLExt.kt
Stub functions: single<T>(), factory<T>()
ModuleExt.kt
Target functions: buildSingle(), buildFactory()
ViewModelDSLExt.kt
Stub functions: viewModel<T>()
WorkerDSLExt.kt
Stub functions: worker<T>()
CreateDSL.kt
Stub functions: Scope.create(::T) (constructor reference)
FIR Phase (declarations) IR Phase (bodies/transformations)
│ │
▼ ▼
┌────────────────────┐ ┌──────────────────────────────────┐
│ KoinModuleFirGen │ │ IR-0: KoinHintTransformer │
│ - @Module scan │ │ IR-1: KoinAnnotationProcessor │
│ - .module property │ → │ IR-2: KoinDSLTransformer │
│ - hint functions │ │ IR-3: KoinStartTransformer │
└────────────────────┘ └──────────────────────────────────┘
Common Debugging Scenarios
"single() not transforming"
Check IR logs: grep "Intercepting single" compilation.log
Verify receiver type is from org.koin.core or org.koin.dsl
See DEBUGGING.md#transformation-not-happening
".module property not found"
Verify class has BOTH @Module AND @ComponentScan
Enable debug logs: koinCompiler { debugLogs = true } and check compilation output
See DEBUGGING.md#module-property-not-generated
Check @KoinApplication(modules = [...]) annotation
Cross-module discovery is limited - use explicit modules
See DEBUGGING.md#no-modules-to-inject