0.4.0
Pre-releaseNative Kotlin Compiler Plugin for Koin — K2 Required (Kotlin 2.3.x+) | Koin 4.2.0-RC2+
Highlights
Compile-Time Dependency Safety is the headline feature of 0.4.0. The plugin now validates your entire dependency graph at compile time, catching missing bindings before they become runtime crashes.
New Features
Compile-Time Safety Checks (compileSafety = true, on by default)
Multi-layered validation that progressively widens visibility:
- A1 — Per-Module: validates definitions within a single @module plus its explicit includes
- A2 — Configuration Groups: modules sharing a @configuration label are validated together
- A3 — Full Graph (startKoin): validates the complete assembled graph when using @KoinApplication
- A4 — Call-Site Validation: checks get(), inject(), and koinViewModel() call sites against the known graph
- B — DSL Definitions: single(), factory(), etc. participate in the safety graph alongside annotation-based definitions
- C — Cross-Gradle-Module: definitions from dependency JARs are discovered via hint functions
- C2 — Full Hint Metadata: cross-module function hints now carry qualifier, scope, and binding information
Catches missing non-nullable dependencies, unresolved Lazy, qualifier mismatches, and cross-scope errors at compile time. Nullable params, @InjectedParam, @Property, List, and defaulted
parameters are safely skipped.
@provided Annotation
Mark types as externally available at runtime (e.g., platform types not declared as Koin definitions). Safety checks will skip them.
@Provided
class ExternalService // provided by framework at runtime
@Singleton
class MyService(val ext: ExternalService) // no errorAndroid Framework Whitelist
Common Android types are automatically whitelisted — no @provided needed:
Context, Activity, Application, Fragment, SavedStateHandle, WorkerParameters
@monitor Annotation
Function interception for logging and performance monitoring:
@Monitor
class MyService {
fun fetchData(): Data { ... } // calls intercepted with timing/logging
}skipDefaultValues Option (default: true)
Parameters with Kotlin default values are no longer injected from the DI container by default. Annotated and nullable parameters are still resolved normally.
class Service(val a: A, val name: String = "default")
single<Service>()
// Generated: Service(scope.get()) — name uses Kotlin default
Incremental Compilation Support
Dirty marker / IC recompilation detection ensures the plugin cooperates correctly with Kotlin's incremental compilation.
KMP Improvements
- Full hint function generation for JVM, JS, and Wasm targets
- @deprecated(HIDDEN) on generated hints to avoid polluting IDE autocomplete
- Fix for @configuration and @componentscan detection in multi-target builds
- KLIB workaround extended to JS and Wasm targets
Configuration
koinCompiler {
compileSafety = true // Compile-time dependency validation (default: true)
unsafeDslChecks = true // Validate create() is sole lambda instruction (default: true)
skipDefaultValues = true // Skip injection for defaulted params (default: true)
userLogs = true // Component detection logs
debugLogs = true // Verbose internal logs
}Compatibility
- Kotlin: 2.3.x+ (K2 compiler required)
- Koin: 4.2.0-RC2+