Skip to main content
Version: 4.2

Gradle Setup

This page lists the Gradle dependencies for each platform and every published Koin artifact. Samples use the Kotlin DSL (build.gradle.kts) and a version catalog. To add compile-time checks and the Compiler Plugin DSL, also follow Compiler Plugin Setup.

Versions​

All Koin libraries, including koin-annotations, share one version. The current stable version is 4.2.2.

  • Koin: Maven Central

All artifacts are on Maven Central under the group io.insert-koin. Version history and upgrade notes are in Releases.

Koin BOM​

The Koin BOM (bill of materials) pins every Koin library to the same version. You declare the BOM version once and add Koin libraries without a version. When you update the BOM, all Koin libraries move together.

In gradle/libs.versions.toml:

[versions]
koin = "4.2.2"

[libraries]
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-android = { module = "io.insert-koin:koin-android" }
koin-compose = { module = "io.insert-koin:koin-compose" }
koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel" }
koin-compose-viewmodel-navigation = { module = "io.insert-koin:koin-compose-viewmodel-navigation" }
koin-ktor = { module = "io.insert-koin:koin-ktor" }
koin-logger-slf4j = { module = "io.insert-koin:koin-logger-slf4j" }
koin-annotations = { module = "io.insert-koin:koin-annotations" }
koin-test = { module = "io.insert-koin:koin-test" }
koin-test-junit4 = { module = "io.insert-koin:koin-test-junit4" }

In your module's build.gradle.kts:

dependencies {
implementation(platform(libs.koin.bom))
implementation(libs.koin.android)
}

Without a version catalog:

dependencies {
implementation(platform("io.insert-koin:koin-bom:4.2.2"))
implementation("io.insert-koin:koin-android")
testImplementation("io.insert-koin:koin-test-junit4")
}

A version written on one dependency overrides the BOM for that dependency only. Avoid it unless you need a fix from a newer release of one library.

Without the BOM​

You can also put the version on each library. This is what the Koin samples do, and it works the same in Kotlin Multiplatform source sets:

[versions]
koin = "4.2.2"

[libraries]
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }

Keep a single koin version for all Koin libraries: mixing versions is not supported.

Kotlin/JVM​

dependencies {
implementation(platform(libs.koin.bom))
implementation(libs.koin.core)
}

Then start Koin in main. See Starting Koin and the Kotlin tutorial.

Android​

dependencies {
implementation(platform(libs.koin.bom))
implementation(libs.koin.android)
}

koin-android includes koin-core and the ViewModel support. Start Koin in your Application class: see Start Koin on Android.

Optional Android libraries:

ArtifactAdds
koin-androidx-workmanagerWorkManager workers: see WorkManager
koin-androidx-navigationViewModels scoped to a Navigation graph (Fragments)
koin-androidx-startupStart Koin with AndroidX App Startup
koin-android-compatJava helpers to inject from Java classes
koin-dagger-bridgeUse Dagger components from Koin during a migration

Android with Jetpack Compose​

dependencies {
implementation(platform(libs.koin.bom))
implementation(libs.koin.android)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
}

koin-androidx-compose is an Android-only artifact that brings koin-compose and koin-compose-viewmodel in one dependency. Either setup works.

For navigation, add one of:

ArtifactNavigation library
koin-androidx-compose-navigationNavigation Compose 2, Android only
koin-compose-viewmodel-navigationNavigation Compose 2, multiplatform
koin-compose-navigation3Navigation 3: see Navigation 3

See Koin for Compose for the APIs.

Compose Multiplatform​

In the shared module, add the Compose libraries to commonMain. In multiplatform source sets, use catalog entries that carry the version (see Without the BOM):

kotlin {
sourceSets {
commonMain.dependencies {
implementation(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.koin.compose.viewmodel.navigation) // if you use Navigation Compose
}
}
}

On Android, koin-compose brings koin-android, so you don't need to add it. See the Compose Multiplatform tutorial.

Kotlin Multiplatform​

In the shared module's build.gradle.kts, with catalog entries that carry the version (see Without the BOM):

kotlin {
sourceSets {
commonMain.dependencies {
implementation(libs.koin.core)
}
androidMain.dependencies {
implementation(libs.koin.android)
}
commonTest.dependencies {
implementation(libs.koin.test)
}
}
}

koin-core supports JVM, Android, Apple targets (iOS, macOS, tvOS, watchOS), Linux, Windows, JS and Wasm (wasmJs). Project structure and platform-specific definitions are covered in Kotlin Multiplatform Setup.

Ktor​

dependencies {
implementation(platform(libs.koin.bom))
implementation(libs.koin.ktor)
implementation(libs.koin.logger.slf4j)
}

Install the Koin plugin in your Ktor application: see Koin for Ktor.

Testing​

dependencies {
testImplementation(libs.koin.test)
testImplementation(libs.koin.test.junit4) // or koin-test-junit5
}

For Android instrumented tests, add koin-android-test to androidTestImplementation. See Injecting in Tests and Android Instrumented Testing.

All artifacts​

ArtifactPlatformsDescription
koin-bomAllBill of materials for every artifact below
koin-coreAllContainer, DSL, scopes, Compiler Plugin DSL
koin-core-coroutinesAllLazy modules and background loading
koin-core-viewmodelAllViewModel definitions for Android and Compose Multiplatform
koin-annotationsAllAnnotations for the Compiler Plugin (@Singleton, @Module, @Named, ...)
koin-androidAndroidAndroid context, Activity and Fragment APIs, ViewModel
koin-android-compatAndroidJava compatibility helpers
koin-androidx-navigationAndroidNavigation graph scoped ViewModels
koin-androidx-workmanagerAndroidWorkManager integration
koin-androidx-startupAndroidAndroidX App Startup integration
koin-dagger-bridgeAndroidAccess Dagger components from Koin
koin-composeAll Compose targetskoinInject(), KoinApplication and Compose context
koin-compose-viewmodelAll Compose targetskoinViewModel()
koin-compose-viewmodel-navigationAll Compose targetsViewModels scoped to a Navigation Compose back stack entry
koin-compose-navigation3All Compose targetsNavigation 3 integration
koin-androidx-composeAndroidBundle of koin-compose and koin-compose-viewmodel for Android
koin-androidx-compose-navigationAndroidNavigation Compose 2 for Android
koin-ktorJVM, JS, Wasm, iOS, macOS (Ktor server targets)Ktor server plugin
koin-logger-slf4jJVMSLF4J logger
koin-testAllTest API: KoinTest, verify()
koin-test-coroutinesJVMVerification for lazy modules
koin-test-junit4JVMJUnit 4 rules
koin-test-junit5JVMJUnit 5 extensions
koin-android-testAndroidInstrumented test helpers

The Koin Compiler Plugin is a Gradle plugin, not a library: it has its own version. See Compiler Plugin Setup.