Build Lifecycle
Status: 🟢 Phases 1 and 3 through 8 run today. 🟡 Variant resolution and ⚪ hook dispatch are not wired in. See Implementation Status.
What happens between kargo build and a JAR. Useful when a build surprises you;
not required reading.
graph TD
LOAD["1 · Load manifest"] --> VARIANTS["2 · Resolve variants"]
VARIANTS --> RESOLVE["3 · Resolve dependencies"]
RESOLVE --> FETCH["4 · Fetch artifacts"]
FETCH --> PLAN["5 · Plan the unit graph"]
PLAN --> CODEGEN["6 · Generate code"]
CODEGEN --> COMPILE["7 · Compile"]
COMPILE --> PACKAGE["8 · Package"]
The order is fixed. Kargo has no user-defined task graph, which is the trade it makes: less expressive than Gradle, and far easier to reason about when something goes wrong.
1. Load the manifest
Read Kargo.toml, interpolate ${env:…} from .kargo.env and the environment,
parse, and validate. Validation happens here so a typo in a version string fails
in milliseconds rather than after a download.
2. Resolve variants
🟡 Not applied yet.
Expand [flavors] × profiles into variants, subtract
exclusions, and select which to build from --variant, --flavor, or the
configured default.
3. Resolve dependencies
With a current lockfile, this is a read. Otherwise Kargo fetches POMs, walks the
transitive graph, mediates conflicts nearest-wins, and writes
Kargo.lock.
4. Fetch artifacts
Download whatever the lockfile names and is not already in ~/.kargo/cache/,
verifying checksums. --offline skips the network and fails if anything is
missing.
5. Plan the unit graph
⚪ One unit, not a graph, today: every main source set is flattened into a single
mainunit, andkargo testcompiles atestunit after it. The graph is the model being built towards, not what the build plans now.
Discover source sets from the project layout and build a graph of compilation units. Each unit is one compiler invocation; edges are "must compile before".
Each unit is then fingerprinted — source hashes, dependency set, compiler arguments, compiler version, target — and units whose fingerprint is unchanged are dropped from the plan. See Incremental Compilation.
6. Generate code
BuildConfig from [build-config] and flavors, then KSP and
KAPT processors. Generated sources
are added to their units and included in the fingerprint, so generated code
participates in incremental builds correctly.
7. Compile
Surviving units are dispatched to the compiler backend for their target —
kotlinc, kotlinc-js, or kotlinc-native.
⚪ Compilation is single-threaded. There is one unit per build, so there is nothing to overlap, and
[build] jobsbounds nothing today — seejobs.
A fingerprint miss checks the build cache before actually compiling; a hit restores the output instead.
8. Package
Assemble the output for the target: a JAR for the JVM, a klib or framework for
Native, a bundle for JS. kargo package does more
elaborate work on top of this.
Resources are staged beside the classes here, and this phase decides for itself whether to run: it has its own fingerprint over the resource files, so editing only a resource rebuilds the JAR without recompiling anything, and editing only Kotlin does not re-read the resources.
Where hooks fire
⚪ Planned.
Every phase boundary is a hook point:
| Boundary | Hooks |
|---|---|
| Around phase 3 | pre-resolve, post-resolve |
| Around phase 4 | pre-fetch, post-fetch |
| Around phases 5–8 | pre-build, post-build |
| Around phase 7 | pre-compile, post-compile |
| Per variant | pre-variant-build, post-variant-build |
A non-zero exit from a pre-* hook stops the build.
What the other commands do
| Command | Phases |
|---|---|
kargo check | 1–7, no artifact assembly |
kargo test | 1–8, then compile and run test units |
kargo fetch | 1, 3, 4 |
kargo lock | 1, 3 |
kargo tree | 1, 3, then print |
kargo run | 1–8, then execute |
This is why kargo check is the fast feedback loop: it does everything that
finds errors and nothing that assembles an artifact. It still runs phase 6 —
skipping it would have the type-check miss the generated sources and report
unresolved references to code the build compiles — and the classes phase 7
produces go to a temporary directory it discards.