A native Kotlin Compiler Plugin for Koin dependency injection. Write single<T>() instead of singleOf(::T), use @Singleton/@Factory annotations - all resolved at compile-time by the Kotlin compiler, no KSP required.
// build.gradle.kts
plugins {
id("io.insert-koin.compiler.plugin") version "0.3.0"
}
dependencies {
implementation("io.insert-koin:koin-core:4.2.0")
// If using annotations
implementation("io.insert-koin:koin-annotations:4.2.0")
}Important: Use imports from
org.koin.plugin.module.dsl, not the classic Koin DSL.
import org.koin.plugin.module.dsl.single
import org.koin.plugin.module.dsl.factory
import org.koin.plugin.module.dsl.viewModel
import org.koin.plugin.module.dsl.worker
val myModule = module {
single<MyService>()
factory<MyRepository>()
viewModel<MyViewModel>()
worker<MyWorker>() // Android WorkManager
}@Module
@ComponentScan
class AppModule
@Singleton
class MyService(val repo: Repository)
@Factory
class MyRepository
@KoinViewModel
class MyViewModel(val service: MyService) : ViewModel()@KoinApplication(modules = [AppModule::class])
object MyApp
fun main() {
startKoin<MyApp> {
printLogger()
}
}- DSL Transformation:
single<T>(),factory<T>(),viewModel<T>(),worker<T>(),scoped<T>() - Annotation Processing:
@Singleton,@Factory,@KoinViewModel,@Scoped,@KoinWorker - Auto Module Injection:
@KoinApplication(modules = [...])withstartKoin<App>() - Full KMP Support: JVM, JS, WASM, iOS, macOS, watchOS, tvOS, Linux, Windows
- JSR-330 Support:
@Inject,@Namedfromjavax.injectorjakarta.inject
// build.gradle.kts
koinCompiler {
userLogs = true // Log component detection
debugLogs = true // Log internal processing (verbose)
}- Koin: 4.2.0-RC1+
- Kotlin: K2 compiler required (2.3.x+)
See the docs/ folder:
- MIGRATION_FROM_KSP.md - Migration from Koin Annotations (KSP)
- CASE_STUDY_NOW_IN_ANDROID.md - Real-world migration case study
- DEBUGGING.md - Debugging guide and common issues
- ARCHITECTURE.md - Project structure and compilation flow
- TRANSFORMATIONS.md - All transformation examples
- ROADMAP.md - Project status and future plans
# Build and install to Maven Local
./install.sh
# Run tests
./gradlew :koin-compiler-plugin:test
# Run sample (from test-apps/)
cd test-apps && ./gradlew :sample-app:jvmRunApache 2.0