Kotlin Multiplatform
Status: 🟡 Partial — targets are declared in the manifest, and JVM, Android, JS, and Native compiler backends exist. Source sets are discovered, inferred into a hierarchy, and overridable from the manifest. Today each target builds separately via
--target; a single-pass multi-target build andexpect/actualvalidation are in progress. See Implementation Status.
Multiplatform in Kargo is a list of targets in the manifest. There is no plugin to
apply and no kotlin { } block to configure.
[targets]
jvm = { java-target = "25" }
android = { min-sdk = 24, target-sdk = 36, compile-sdk = 36 }
ios-arm64 = {}
ios-simulator-arm64 = {}
js = { module-kind = "es" }
Start one with kargo new my-shared --template kmp.
Source sets
Each target reads from its own directory, plus commonMain for shared code:
src/
├── commonMain/kotlin/ # compiled into every target
├── commonTest/kotlin/
├── jvmMain/kotlin/
├── jvmTest/kotlin/
├── iosMain/kotlin/ # shared by every iOS target
├── iosArm64Main/kotlin/ # one specific iOS target
└── jsMain/kotlin/
The directory name is the configuration: src/<sourceSet>/kotlin, where the
source set is the target name in camelCase plus Main or Test.
expect and actual
Declare the shape in common code, implement it per platform:
// src/commonMain/kotlin/Platform.kt
expect fun platformName(): String
expect class HttpClient() {
suspend fun get(url: String): String
}
// src/jvmMain/kotlin/Platform.kt
actual fun platformName(): String = "JVM ${System.getProperty("java.version")}"
// src/iosMain/kotlin/Platform.kt
import platform.UIKit.UIDevice
actual fun platformName(): String =
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
expect/actual validation
Status: ⚪ Planned.
Before compiling, Kargo checks that every expect declaration has a matching
actual in each configured target, and reports the gaps together:
error: missing actual declarations
expect fun platformName() declared in src/commonMain/kotlin/Platform.kt:3
missing for target js
missing for target wasm-js
2 declarations missing actuals across 2 targets
The point is to fail with a list rather than one compiler error per target, which is the normal experience when a target is added late.
The source-set hierarchy
Writing the same iOS code twice — once for iosArm64Main, once for
iosSimulatorArm64Main — is the failure mode this prevents. Kargo infers
intermediate source sets shared by families of targets:
graph TD
COMMON["commonMain"] --> NATIVE["nativeMain"]
COMMON --> JVM["jvmMain"]
COMMON --> JSWASM["jsAndWasmMain"]
NATIVE --> APPLE["appleMain"]
NATIVE --> LINUX["linuxX64Main"]
APPLE --> IOS["iosMain"]
APPLE --> MACOS["macosMain"]
IOS --> IOSARM["iosArm64Main"]
IOS --> IOSSIM["iosSimulatorArm64Main"]
JSWASM --> JS["jsMain"]
JSWASM --> WASM["wasmJsMain"]
So code in iosMain compiles into both iOS targets; code in appleMain reaches
macOS, tvOS, and watchOS too. You only create the directories you actually use.
Override the inferred graph when you need something it does not provide — a set shared by the JVM and Android targets and only those two:
[source-sets.jvmAndAndroidMain]
depends-on = ["commonMain"]
targets = ["jvm", "android"]
Full rules in the Source Sets reference.
Target-specific dependencies
[dependencies]
kotlinx-coroutines-core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"
[target.jvm.dependencies]
ktor-client-okhttp = "io.ktor:ktor-client-okhttp:2.3.0"
[target.ios.dependencies]
ktor-client-darwin = "io.ktor:ktor-client-darwin:2.3.0"
[target.js.dependencies]
ktor-client-js = "io.ktor:ktor-client-js:2.3.0"
[dependencies] must resolve for every target, so only multiplatform artifacts
belong there. Platform-only libraries go under their target.
Kargo reads Gradle Module Metadata
where artifacts publish it, which is how a single coordinate such as
io.ktor:ktor-client-core resolves to the right platform artifact.
Building
kargo build --target jvm
kargo build --target ios-arm64
kargo test --target jvm
Status: 🟡 One target per invocation today. A single command that compiles
commonMainonce and fans out to every target is the current phase of work.
Native targets need a matching host: Apple targets require macOS with Xcode; no host cross-compiles to iOS.
CInterop
Status: ⚪ Planned.
Call C and Objective-C libraries from Kotlin/Native:
[target.ios-arm64.cinterop.mylib]
def-file = "src/nativeInterop/cinterop/mylib.def"
headers = ["include/mylib.h"]
compiler-opts = ["-Iinclude"]
linker-opts = ["-L/usr/local/lib", "-lmylib"]
Kargo runs the cinterop tool to generate bindings before compiling, and adds
them to the target's classpath automatically.
Consuming the result
| Target | Artifact | Consumed by |
|---|---|---|
jvm | JAR | Any JVM project |
android | JVM classes (AAR packaging planned) | Android apps |
ios-* | .framework, or an XCFramework via packaging | Xcode projects |
js | .js plus .d.ts | npm consumers, bundlers |
linux-x64, mingw-x64, macos-* | Executable or shared library | Native consumers |
Choosing targets
Every target you add multiplies build time, test surface, and the number of
actual implementations you owe. Add them when you need them — the manifest edit
is one line, so there is no reason to add a target speculatively.
Next
- Compose Multiplatform — shared UI on top of shared logic
- Targets reference — every target and its options
- Source Sets reference