Building and Running
Status: 🟢 Implemented for one target per invocation, with incremental compilation and the local build cache. 🟡
--flavor,--variant, and--all-variantsare accepted but currently ignored. See Implementation Status.
The four commands
kargo build # compile to artifacts
kargo run # compile, then execute
kargo check # type-check only, no artifacts
kargo clean # delete outputs
kargo check is the one to bind to a keystroke. It skips artifact assembly and
discards the classes it produces, so it answers "does this compile" in a
fraction of a build.
Building
kargo build
Resolving dependencies
Compiling my-service v1.2.0 (jvm, dev)
Finished dev profile in 3.14s
A build with an up-to-date Kargo.lock does no resolution work: it reads locked
versions, verifies cached artifacts, and compiles.
Flags
| Flag | Effect |
|---|---|
-t, --target <name> | Build one target. Defaults to the only target, or jvm. |
-p, --profile <name> | Build with a named profile. Default dev. |
--release | Shorthand for --profile release. |
--offline | Resolve only from the local cache; never touch the network. |
--timings | Print per-phase timing. |
-v, --verbose | Full compiler command lines and resolution detail. |
-q, --quiet | Print only warnings and errors. |
--flavor <name> | 🟡 Accepted, not yet applied. |
--variant <name> | 🟡 Accepted, not yet applied. |
--all-variants | 🟡 Accepted, not yet applied. |
Where output goes
build/<target>/<profile>/
├── classes/ # compiled classes or klibs
└── output/
└── my-service-1.2.0.jar
Each target-and-profile pair owns its directory, so switching between dev and
release never invalidates the other's work.
Incremental fingerprints live in .kargo/fingerprints/, outside build/.
Running
kargo run
Requires main-class in [package]:
[package]
main-class = "com.example.MainKt"
Pass arguments to your program after --, so they are not parsed as Kargo flags:
kargo run -- --port 8080 --verbose
kargo run --release # run the optimized build
kargo run --target jvm # pick a target explicitly
Your program gets the terminal Kargo was started on. Its output appears as it is written rather than when it exits, it reads the real stdin, and Ctrl-C stops it — so a server logs the port it bound while it is serving, and a program that prompts for input can be answered.
Stopping Kargo stops your program with it, including when a supervisor or a
container sends SIGTERM rather than you pressing Ctrl-C. Nothing is left
holding the port your next run needs.
Type-checking
kargo check
Runs the compiler front end — resolution, type checking, diagnostics — without writing artifacts. Use it in editors, pre-commit hooks, and the fast lane of CI.
It checks the same sources a build compiles, which means it generates
BuildConfig.kt and runs the [ksp] and [kapt] processors first. Those are
cached, and so is the type-check itself: a second kargo check over an
unchanged tree reports check up-to-date without starting the compiler.
Cleaning
kargo clean # all of build/ plus fingerprints
kargo clean --variant jvm/dev # just one target and profile
A clean build is rarely the fix for a wrong build. If you reach for kargo clean
to work around staleness, that is a bug worth
filing — incremental
compilation is supposed to be correct, not merely fast.
Watching
kargo watch # rebuild and re-run on change
kargo watch --build-only # rebuild only
Watches your source directories and Kargo.toml, debounces bursts of saves, and
cancels an in-flight build when a newer change arrives.
Detected change at 14:03:12, rebuilding...
Compiling my-service v1.2.0 (jvm dev)
Finished 14 source file(s) [jvm dev] in 7.86s
Watching for changes...
A program that is still running is stopped before the rebuild and started again after it, which is what makes watching a server work: the watcher stays live while the program serves, and each change restarts it.
Stopping com.example.ApplicationKt
Detected change at 14:03:12, rebuilding...
Compiling my-service v1.2.0 (jvm dev)
Finished 14 source file(s) [jvm dev] in 7.86s
Watching for changes...
Running com.example.ApplicationKt
A program that ends by itself is reported the moment it does, not at your next
save. Nothing else would tell you: watch keeps going rather than exiting with
the program's status, so a service that crashed would otherwise look exactly
like one still serving.
! Exited com.example.ApplicationKt: exit code: 1
Watching for changes...
Ending the session takes the running program with it, the same way
kargo run does.
Why it is fast
Three mechanisms, in order of how often they save you time:
1. Fingerprinting. Before compiling a unit, Kargo hashes its inputs: source contents, the resolved dependency set, compiler arguments, compiler version, and target. Unchanged fingerprint, no compile. This is why a no-op build finishes in milliseconds.
2. The build cache. A fingerprint miss checks the content-addressed build cache before compiling. Switching branches back and forth usually hits it.
3. No configuration phase. Kargo is a native binary that reads a TOML file. There is no build script to compile, no plugin graph to configure, and no Gradle daemon to keep warm — so the fixed cost before any real work starts is close to zero.
The Kotlin compiler itself still runs on the JVM, and Kargo reuses the Kotlin
compile daemon across invocations so that cost is paid once rather than per build.
kargo cache stop-daemon shuts it down when you want a cold measurement.
Details in Incremental Compilation.
Measuring a slow build
kargo build --timings
Resolving dependencies .... 0.31s
Fetching artifacts ....... 1.20s
Compiling commonMain ..... 2.14s
Compiling jvmMain ........ 1.83s
Packaging ................ 0.42s
Total .................... 5.90s
Read it as a triage tool:
| Dominant phase | Likely cause |
|---|---|
| Resolving | No lockfile, or kargo update ran. Commit Kargo.lock. |
| Fetching | Cold artifact cache. Run kargo fetch before the timed build. |
| Compiling | Genuine compile cost — or fingerprint misses. Try -v. |
| Packaging | Large fat JAR or many resources. |
Status: ⚪
--timings=htmlfor an interactive timeline is planned.
Building for several targets
Today, one target per invocation:
kargo build --target jvm
kargo build --target ios-arm64
Status: 🟡 A single-pass multi-target build — one command that compiles
commonMainonce and fans out to every configured target — is the next phase of work. See Kotlin Multiplatform.
Reproducible builds
For a build that produces identical artifacts anywhere:
- Commit
Kargo.lock. - Pin
kotlinto an exact version (no ranges — the field does not accept them). - Build with
--offlineafter akargo fetch, so the network cannot change the inputs. - Keep
[profile.*]settings in the manifest rather than passing ad-hoc compiler flags.
Checksums for every artifact are verified on every build, cached or not, so a tampered or truncated download fails loudly instead of producing a mystery compile error.
Next
- Build Profiles — dev, release, and custom profiles
- The Build Cache — local and remote caching
- Testing — running tests
- Troubleshooting — when a build fails