Source Sets
Status: 🟢 Conventional directories are discovered, the intermediate source sets are inferred from the target list, and
[source-sets.*]overrides what either of those would decide. See Implementation Status.
A source set is a directory of code compiled into one or more targets. Kargo discovers them by name; there is nothing to declare.
Naming
src/<sourceSetName>/kotlin # Kotlin sources
src/<sourceSetName>/resources # bundled resources
src/<sourceSetName>/composeResources # Compose assets
The name is the target in camelCase plus Main or Test:
| Source set | Compiled into |
|---|---|
commonMain | every target |
commonTest | every target's tests |
jvmMain | jvm |
androidMain | android |
jsMain | js |
iosArm64Main | ios-arm64 |
iosSimulatorArm64Main | ios-simulator-arm64 |
linuxX64Main | linux-x64 |
Single-target JVM projects use the Maven layout instead — src/main/kotlin and
src/test/kotlin — which is what kargo new generates for the jvm and lib
templates.
The hierarchy
Writing identical iOS code in iosArm64Main and iosSimulatorArm64Main is the
problem intermediate source sets solve. Kargo infers them from your target list:
graph TD
COMMON["commonMain"] --> NATIVE["nativeMain"]
COMMON --> JVM["jvmMain"]
COMMON --> ANDROID["androidMain"]
COMMON --> JSWASM["jsAndWasmMain"]
NATIVE --> APPLE["appleMain"]
NATIVE --> LINUX["linuxMain"]
NATIVE --> MINGW["mingwMain"]
NATIVE --> ANDROIDNATIVE["androidNativeMain"]
APPLE --> IOS["iosMain"]
APPLE --> MACOS["macosMain"]
APPLE --> TVOS["tvosMain"]
APPLE --> WATCHOS["watchosMain"]
IOS --> IOSARM["iosArm64Main"]
IOS --> IOSSIM["iosSimulatorArm64Main"]
LINUX --> LINUXX64["linuxX64Main"]
JSWASM --> JS["jsMain"]
JSWASM --> WASM["wasmJsMain"]
JSWASM --> WASI["wasmWasiMain"]
| Intermediate set | Covers |
|---|---|
nativeMain | every Kotlin/Native target |
appleMain | iOS, macOS, tvOS, watchOS |
iosMain | every iOS target |
macosMain | macOS targets |
tvosMain | tvOS targets |
watchosMain | watchOS targets |
linuxMain | Linux targets |
mingwMain | Windows targets |
androidNativeMain | Android NDK targets |
jsAndWasmMain | js, wasm-js, wasm-wasi |
Only the directories you create exist. A project with one iosMain and no
iosArm64Main is normal and correct, and so is a gap in the middle: with
appleMain and iosArm64Main but no iosMain, the leaf depends on appleMain
directly.
Each *Main set has a matching *Test set with the same relationships, and
also sees its own *Main.
What goes where
| Code | Source set |
|---|---|
| Business logic, models, use cases | commonMain |
An expect declaration | commonMain |
| JVM file I/O, JDBC, servlets | jvmMain |
Context, Activity, Android APIs | androidMain |
UIKit, Foundation, anything from platform.* | iosMain |
| Browser DOM access | jsMain |
| POSIX calls shared by Linux and Apple | nativeMain |
The rule of thumb: put code as high in the hierarchy as it compiles. Code in
commonMain is tested once and works everywhere; code pushed down into a
platform set has to be written and tested per platform.
Dependencies between source sets
A source set sees everything its ancestors declare. So iosArm64Main can use
anything from iosMain, appleMain, nativeMain, and commonMain.
Target-specific dependencies follow the same path:
[dependencies]
ktor-client-core = "io.ktor:ktor-client-core:2.3.0" # commonMain and below
[target.ios.dependencies]
ktor-client-darwin = "io.ktor:ktor-client-darwin:2.3.0" # iosMain and below
Resources
src/commonMain/resources/ # every target
src/jvmMain/resources/ # jvm only
src/commonMain/composeResources/ # Compose: typed Res accessors
Resources merge along the hierarchy, with the more specific set winning on a name collision — how a platform substitutes one asset without duplicating the rest.
Flavor source sets
Status: 🟡 Specified; not applied to builds yet.
Flavors add a dimension, composing most-specific-last:
src/
├── commonMain/kotlin/ # all targets, all flavors
├── jvmMain/kotlin/ # jvm, all flavors
├── freeMain/kotlin/ # free, all targets
├── freeJvmMain/kotlin/ # free, jvm only
└── paidIosMain/kotlin/ # paid, ios only
Explicit overrides
For layouts that cannot move — a migrating project, generated code in an unusual location:
[source-sets.jvmMain]
kotlin = ["legacy/src/java", "build/generated/kotlin"]
resources = ["legacy/src/resources"]
depends-on = ["commonMain"]
| Key | Type | Description |
|---|---|---|
kotlin | list | Source roots, relative to the project root, replacing the convention. |
resources | list | Resource roots, replacing the convention. |
depends-on | list | Parent source sets, replacing the inferred parent. |
targets | list | Targets this set compiles into. |
A key you leave out keeps the convention, so moving the sources says nothing
about the resources; an empty list is the same as leaving the key out, since a
source set with no sources is one you simply do not declare. The name decides
which compilation the set joins: main and test in the Maven layout, a name
ending in Main or Test in this one.
Declaring a set is what brings it into existence. src/jvmMain need not exist
for [source-sets.jvmMain] to be compiled, which is the point when the code is
somewhere else entirely.
Parents you wire yourself
depends-on replaces the inferred parent rather than adding to it, so a set
that names one is out of the hierarchy's hands:
[source-sets.iosArm64Main]
depends-on = ["appleMain"]
With that, iosArm64Main hangs off appleMain even when iosMain exists, and
iosMain is no longer compiled into ios-arm64 — nothing in that target's
chain reaches it any more.
Groupings the hierarchy does not have
The standard hierarchy has no set shared by the JVM and Android targets and only
those two. targets declares one:
[source-sets.jvmAndAndroidMain]
depends-on = ["commonMain"]
targets = ["jvm", "android"]
Each target named gains the set, and that target's own set hangs off it:
jvmMain sat under commonMain and now sits under jvmAndAndroidMain. A
target with no set of its own — a project whose JVM and Android code is entirely
shared creates no jvmMain — compiles the grouping directly.
Only the target's own set moves. An intermediate such as iosMain is shared
with every iOS target beneath it, so a grouping naming ios-arm64 alone is
compiled into ios-arm64 without ios-simulator-arm64 inheriting it. To put a
set above a shared intermediate, name every target under it.
src/jvmAndAndroidTest, if it exists, is grouped the same way without declaring
it twice, exactly as the inferred hierarchy mirrors itself. A set the manifest
wires with its own depends-on keeps those parents, which is how a grouping is
overruled for one target.
A name Kargo does not recognize as a target, and a depends-on cycle, are both
rejected when the manifest loads.
Troubleshooting
My file is not being compiled. Check the directory name against the table
above. src/ios/kotlin is not a source set; src/iosMain/kotlin is.
Why does commonMain not see a dependency? A dependency declared under
[target.jvm.dependencies] is only visible from jvmMain down. Common code
needs it in [dependencies], which means it must be a multiplatform artifact.