Dependency Resolution
Status: 🟢 Implemented — POM inheritance, BOM imports, nearest-wins mediation, scopes, exclusions, and SNAPSHOT handling all work.
Resolution turns what you declared into exactly which artifact versions get compiled against. Kargo follows Maven's semantics, because that is what the artifacts in Maven Central were published under.
The algorithm
- Start from your direct dependencies at depth 0.
- Fetch each artifact's POM and read its dependencies.
- Walk breadth-first, recording the depth at which each artifact is first seen.
- When the same artifact appears at two versions, nearest wins — the shallower depth. Equal depth is broken by declaration order.
- Apply exclusions, drop
optionaldependencies of transitive deps, and filter by scope. - Write the result to
Kargo.lockwith a checksum per artifact.
Breadth-first is what makes "nearest" meaningful: a direct dependency is always depth 0, so declaring a version directly overrides anything transitive.
Nearest wins, and why it may surprise you
my-app
├── library-a v1.0 → kotlin-stdlib v1.9.0 (depth 1)
└── library-b v2.0
└── library-c v1.5 → kotlin-stdlib v1.9.21 (depth 2)
kotlin-stdlib 1.9.0 wins at depth 1 — even though 1.9.21 is newer.
Gradle would pick 1.9.21, because it resolves to the highest version. This is the single most common surprise when moving a build to Kargo, and it is a deliberate choice: nearest-wins makes the outcome depend on your declarations rather than on what any transitive dependency happens to request, which makes it predictable and stable under dependency updates.
To force a version, declare it:
[dependencies]
kotlin-stdlib = "org.jetbrains.kotlin:kotlin-stdlib:1.9.21"
Depth 0 beats everything.
kargo tree --conflicts # every mediation decision
kargo tree --why some-lib # the path that pulled it in
Scopes
| Scope | Compile | Runtime | Propagates to consumers |
|---|---|---|---|
compile | yes | yes | yes |
runtime | no | yes | yes, as runtime |
provided | yes | no | no |
test | tests only | tests only | no |
import | n/a | n/a | version constraints only |
A transitive compile dependency stays compile. A transitive dependency of a
runtime dependency becomes runtime. provided and test do not propagate at
all — which is why you sometimes have to declare something your dependency also
uses.
Exclusions
[dependencies.some-lib]
group = "com.example"
artifact = "some-lib"
version = "1.0.0"
[[dependencies.some-lib.exclusions]]
group = "org.slf4j"
artifact = "slf4j-log4j12"
[[dependencies.some-lib.exclusions]]
group = "commons-logging" # the whole group
Exclusions apply to that dependency's subtree only. If another path also pulls the excluded artifact in, it still arrives — exclusion is not a global ban.
BOM imports
[dependencies.ktor-bom]
group = "io.ktor"
artifact = "ktor-bom"
version = "2.3.0"
scope = "import"
An imported BOM contributes version constraints and no artifacts. Dependencies with an empty version take theirs from the BOM, including one imported by a POM further up the parent chain. If nothing supplies a version, resolution warns naming the artifact and the POM that declared it, and leaves it out of the graph.
POM features
Kargo implements the parts of the POM format that affect resolution:
| Feature | Behavior |
|---|---|
| Parent inheritance | Walks the parent chain, merging properties, licenses and dependency management |
| Property interpolation | ${project.version} and friends |
dependencyManagement | Version constraints without dependencies |
| Relocation | Follows <relocation> to the artifact's new coordinate |
| Packaging types | jar, pom, aar, klib |
optional | Not propagated transitively |
| Profiles | Activation by property or JDK is not supported |
That last row is deliberate: POM profile activation makes resolution depend on the resolving environment, which breaks reproducibility.
SNAPSHOT versions
A -SNAPSHOT version resolves through the repository's version-level
maven-metadata.xml to a specific timestamped build, and the lockfile records
that exact build — so a snapshot dependency is reproducible until you
deliberately kargo update.
Snapshots and reproducibility remain in tension. Prefer released versions for anything you ship.
Multiplatform resolution
A multiplatform artifact publishes a root module plus one per platform. Kargo reads
Gradle Module Metadata to select the right
platform artifact for each target, and Kargo.lock records which targets each
package belongs to.
Performance
| Mechanism | Effect |
|---|---|
| Lockfile | A current lockfile skips resolution entirely |
| POM cache | POMs are cached in ~/.kargo/cache alongside artifacts |
| Parallel metadata fetch | Independent POMs download concurrently |
| Early termination | A subtree already resolved at a shallower depth is not rewalked |
The practical consequence: commit your lockfile. It is the difference between reading a file and walking a dependency graph over the network.