Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Toolchains

Status: 🟢 Implemented — Kotlin auto-download, JDK and Android SDK installation, and JDK/Android/Apple SDK discovery all work.

Kargo manages the Kotlin compiler the way rustup manages Rust: you declare a version, and the tool makes it exist.

[package]
kotlin = "2.4.21"

That is the entire setup. The first build downloads Kotlin 2.4.21 if it is not cached, and every build after that uses exactly that compiler.

Why this matters

A Kotlin version in a manifest is a version your CI, your laptop, and a new contributor's machine all agree on. The usual alternative is a README line saying "install Kotlin 2.x" — a documented hope rather than a constraint.

Multiple versions coexist, so switching branches switches compilers with nothing to install:

~/.kargo/toolchains/
├── kotlin-2.1.0/
├── kotlin-2.3.1/
└── kotlin-2.4.21/

Managing toolchains

kargo toolchain list              # what is installed
kargo toolchain install 2.4.21    # fetch a version ahead of time
kargo toolchain remove 2.1.0      # reclaim disk
kargo toolchain use 2.4.21        # default for new projects
kargo toolchain path              # where the active one lives
$ kargo toolchain list
  2.1.0
  2.3.1
* 2.4.21     (default)

toolchain use sets the default that kargo new writes into fresh manifests. It does not override an existing project — package.kotlin always wins, which is what makes a checkout reproducible.

toolchain path is for when an external tool needs the compiler:

"$(kargo toolchain path)/bin/kotlinc" -version

Mirrors and air-gapped builds

# ~/.kargo/config.toml
[toolchain]
kotlin-mirror = "https://mirror.example.com/kotlin/releases"
auto-download = true
# Kargo.toml — per project
[toolchain]
jdk = "25"
auto-download = false

Set auto-download = false where outbound network access is unavailable or not allowed. Builds then fail with a message naming the missing version instead of hanging on a download, and you pre-populate ~/.kargo/toolchains/ out of band.

A mirror only needs to serve the same layout as the JetBrains release archive, so a static file server or an artifact proxy is enough.

JDK discovery

Kargo needs a JDK to run the Kotlin compiler and JVM builds. It looks, in order:

  1. [toolchain] jdk in Kargo.toml
  2. [toolchain] jdk in ~/.kargo/config.toml
  3. JAVA_HOME in .kargo.env
  4. JAVA_HOME in the process environment
  5. Common install locations for the platform
[toolchain]
jdk = "/usr/lib/jvm/java-25-openjdk"   # an explicit path
[toolchain]
jdk = "25"                             # a version, matched among discovered JDKs

If no suitable JDK is found, Kargo can fetch one:

kargo toolchain install --jdk          # a sensible default version
kargo toolchain install --jdk 17       # a specific major version
kargo toolchain remove --jdk 17

java-target in [targets.jvm] is a separate decision — the bytecode level you emit, which can be lower than the JDK you compile with:

[targets.jvm]
java-target = "17"      # runs on Java 17+, even if built with JDK 25

Android SDK

export ANDROID_HOME=/path/to/sdk

or, per project:

# .kargo.env
ANDROID_SDK=/Users/jane/Library/Android/sdk

Kargo checks [toolchain], then ANDROID_SDK in .kargo.env, then ANDROID_HOME, then ANDROID_SDK_ROOT, then the platform default. It validates that the platform for your compile-sdk is present and installs it if not.

You can also install the SDK up front:

kargo toolchain install --android          # default compile-sdk level
kargo toolchain install --android 36       # a specific level
kargo toolchain install 2.4.21 --jdk --android   # all three at once
kargo toolchain remove --android

Apple SDKs

On macOS, Kargo resolves SDK paths through xcrun, so whichever Xcode xcode-select points at is what gets used:

xcode-select --install          # command line tools
xcode-select -p                 # which Xcode is active

Apple targets require a macOS host. No other platform cross-compiles to iOS, and Kargo fails early and explicitly rather than part way through a link step.

Disk usage

kargo self info     # versions, paths, cache sizes
kargo self clean    # remove unused toolchains and stale cache entries
$ kargo self info
kargo 0.2.0
  config      ~/.kargo/config.toml
  toolchains  ~/.kargo/toolchains        3 installed, 1.8 GiB
  artifacts   ~/.kargo/cache             4.2 GiB
  build cache ~/.kargo/build-cache       2.1 GiB

A Kotlin toolchain is a few hundred megabytes. kargo self clean keeps the versions your projects reference and drops the rest.

The Kotlin compile daemon

The Kotlin compiler runs on the JVM, and Kargo reuses its compile daemon between invocations so that startup cost is paid once rather than per build. It is managed for you; the only control you need is a way to stop it:

kargo cache stop-daemon

Useful before timing a cold build, or when a compiler upgrade leaves a stale daemon running.

Next