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

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

  1. Start from your direct dependencies at depth 0.
  2. Fetch each artifact's POM and read its dependencies.
  3. Walk breadth-first, recording the depth at which each artifact is first seen.
  4. When the same artifact appears at two versions, nearest wins — the shallower depth. Equal depth is broken by declaration order.
  5. Apply exclusions, drop optional dependencies of transitive deps, and filter by scope.
  6. Write the result to Kargo.lock with 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

ScopeCompileRuntimePropagates to consumers
compileyesyesyes
runtimenoyesyes, as runtime
providedyesnono
testtests onlytests onlyno
importn/an/aversion 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:

FeatureBehavior
Parent inheritanceWalks the parent chain, merging properties, licenses and dependency management
Property interpolation${project.version} and friends
dependencyManagementVersion constraints without dependencies
RelocationFollows <relocation> to the artifact's new coordinate
Packaging typesjar, pom, aar, klib
optionalNot propagated transitively
ProfilesActivation 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

MechanismEffect
LockfileA current lockfile skips resolution entirely
POM cachePOMs are cached in ~/.kargo/cache alongside artifacts
Parallel metadata fetchIndependent POMs download concurrently
Early terminationA 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.

Next