Skip to main content
Version: 3.3

Koin Annotations 1.0

Setup Koin Annotations for your project

Version

koin_ksp_version= "1.0.3"

Everything is hosted on maven central:

// Add Maven Central to your repositories if needed
repositories {
mavenCentral()
}

You can find all Koin packages on maven central.

info

Koin 3.2 or newer is required

KSP Plugin

We need KSP Plugin to work (https://github.com/google/ksp). Jst add the gradle plugin:

ksp_version = "1.6.21-1.0.6""
//at your project root

plugins {
id "com.google.devtools.ksp" version "$ksp_version"
}

Kotlin App Setup

Here below how you can configure a kotlin (even a ktor) app:

// Use KSP Plugin
apply plugin: 'com.google.devtools.ksp'

// Use KSP Generated sources
sourceSets.main {
java.srcDirs("build/generated/ksp/main/kotlin")
}

dependencies {
// Koin
compile "io.insert-koin:koin-core:$koin_version"
compile "io.insert-koin:koin-annotations:$koin_ksp_version"
ksp "io.insert-koin:koin-ksp-compiler:$koin_ksp_version"
}

Android App Setup

Here below how you can configure an Android app:

// Use KSP Plugin
apply plugin: 'com.google.devtools.ksp'

// Use KSP Generated sources
android {
applicationVariants.all { variant ->
variant.sourceSets.java.each {
it.srcDirs += "build/generated/ksp/${variant.name}/kotlin"
}
}
}

dependencies {
// Koin for Android
implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-annotations:$koin_ksp_version"
ksp "io.insert-koin:koin-ksp-compiler:$koin_ksp_version"
}

If you use several KSP libraries (like Room), you can use this way of declaring generated sources:

libraryVariants.all { variant ->
variant.addJavaSourceFoldersToModel(file("build/generated/ksp/${variant.name}/kotlin"))
}

Kotlin KMP Setup

Please follow KSP setup as described in official documentation: KSP with Kotlin Multiplatform

You can also check the Hello Koin KMP project with basic setup for Koin Annotations.