Install

JVM

With Gradle

Add the MavenCentral repository:

buildscript {
    repositories {
        mavenCentral()
    }
}

Then add the dependency:

dependencies {
    implementation 'org.kodein.di:kodein-di:7.22.0'
}

If you are working on a JVM project with Kodein, and are using Proguard to shrink down the size of your application, you must add the following rule to your configuration:

proguard-rules.pro
# Kodein : Keep the generic type information for the dependency container
-keepattributes Signature

Add the dependency:

<dependencies>
    <dependency>
        <groupId>org.kodein.di</groupId>
        <artifactId>kodein-di-jvm</artifactId>
        <version>7.22.0</version>
    </dependency>
</dependencies>
Use kodein-di-jvm, as Kotlin/Multiplatform projects does not work with Maven

Kotlin/Multiplatform (Gradle)

Kodein-DI supports the following targets:
androidArm32, androidArm64, iosArm32, iosArm64, iosX64, linuxArm32Hfp, linuxMips32, linuxMipsel32, linuxX64, macosX64, mingwX64

Kodein-DI uses the new gradle native dependency model.

Add the MavenCentral repository:

buildscript {
    repositories {
        mavenCentral()
    }
}

Then add the dependency:

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation "org.kodein.di:kodein-di:7.22.0"
            }
        }
    }
}

JavaScript (Gradle)

Since Kotlin 1.8, legacy backend has been deprecated, thus starting from 7.17.0 Kodein is only available for JS-IR.

Because Kodein for JavaScript is compiled as a UMD module, it can be imported:

  • In a browser:

    • as an AMD module (for example with RequireJS) (See index.html in the demo project).

    • Directly in an HTML page with a <script> tag (See index2.html in the demo project).

  • In NodeJS, as a regular CJS module.

Add the MavenCentral repository:

buildscript {
    repositories {
        mavenCentral()
    }
}

Then add the dependency:

dependencies {
    compile 'org.kodein.di:kodein-di-js:7.22.0'
}