Setup

Inara ships two artifacts:

Artifact Purpose

org.kodein.di.inara:inara-runtime

The Binding types and the annotations. A normal dependency.

org.kodein.di.inara:inara-processor

The KSP processor that generates module and factory implementations.

Inara runs on KSP but does not install it in your project. You apply the KSP plugin yourself, alongside Inara.

Inara needs KSP 2.3.14 or later: with an older release, the build fails with an error that says so.

KLG

Before running, KSP deletes everything it generated. When Inara reports an error, nothing is generated again: the build fails with that error only, but your IDE no longer finds the builders, Part classes and factory functions, and marks every use of them as an error.

KLG is a Gradle plugin that keeps a copy of each successful KSP generation, and puts it back in place when KSP fails, so that your IDE only shows the error that matters. Inara works without it, but applying it to every project that runs Inara is recommended, as the samples of this page do.

Kotlin Multiplatform

On a multiplatform project, declare your modules in commonMain. The processor then runs once, over the common metadata source set, and its output is fed back into commonMain, so that every target shares a single set of generated implementations:

build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
    kotlin("multiplatform") version "2.4.21"
    id("com.google.devtools.ksp") version "2.3.14"
    id("org.kodein.gradle.klg") version "0.1.0"
}

kotlin {
    jvm()
    iosArm64()
    iosSimulatorArm64()
    // ...your other targets

    sourceSets {
        commonMain {
            kotlin.srcDir(layout.buildDirectory.dir("generated/ksp/metadata/commonMain/kotlin")) (1)
            dependencies {
                implementation("org.kodein.di.inara:inara-runtime:0.4.0")
            }
        }
    }
}

dependencies {
    add("kspCommonMainMetadata", "org.kodein.di.inara:inara-processor:0.4.0") (2)
}

tasks.matching { it.name != "kspCommonMainKotlinMetadata" }.configureEach { (3)
    if (name.startsWith("ksp") || this is KotlinCompilationTask<*>) {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}
1 Adds the generated common sources to commonMain. KSP already registers this directory as an output, but IntelliJ only indexes it as source code if it is also declared here.
2 Runs the processor over the common metadata source set only, rather than once per target.
3 Every compilation, and every per-target KSP task, reads the generated commonMain sources, so all of them must wait for the common KSP task to run.
Inara supports every Kotlin/Native, JS and Wasm target listed in Supported platforms.

JVM

On a JVM-only project, KSP wires its generated sources into the compilation and into the IDE automatically:

build.gradle.kts
plugins {
    kotlin("jvm") version "2.4.21"
    id("com.google.devtools.ksp") version "2.3.14"
    id("org.kodein.gradle.klg") version "0.1.0"
}

dependencies {
    implementation("org.kodein.di.inara:inara-runtime:0.4.0")
    ksp("org.kodein.di.inara:inara-processor:0.4.0")
}

What gets generated

For each @DIModule interface, the processor generates, in the same package:

  • a builder function named after the interface, which you call to build the module;

  • copy<Module> and shadow<Module> functions, which build a variant of an existing module (see Copying a module and Shadowing a module);

  • a setOf<Set> function for each set the module lists;

  • an Inara<Module> implementation class, which is reserved to generated code and should never be referenced directly;

  • a <Module>BindingArguments container, only if a member that the module declares takes several parameters (see Member arguments);

  • a <Module>Part class, only if the module is partial;

  • an inaraSignatureOf<Module> property, also reserved to generated code, which checks that a module of a library is the one other modules were compiled against (see multi-module projects).

For each @DIFactory object, it generates one extension function per annotation (see Building plain classes).

All of it lives in a file named Inara<Name>.kt under build/generated/ksp.