Dependencies
Status: 🟢 Implemented — add, remove, update, fetch, lock, tree, outdated, and audit all work. 🟡 Version catalog references do not resolve yet; see Version Catalogs.
Kargo speaks Maven. Any artifact you can use from Gradle or Maven, you can use from Kargo — same coordinates, same repositories, same resolution semantics.
Adding
kargo add org.jetbrains.kotlinx:kotlinx-coroutines-core
Leave the version out and Kargo asks the repositories for the current release, then writes the version it found:
Added org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 (latest) to [dependencies]
It never picks a snapshot, so the version you get is one a plain kargo build
can resolve. Pin a version instead by naming it, in the coordinate or as a flag:
kargo add org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0
kargo add org.jetbrains.kotlinx:kotlinx-coroutines-core --version 1.8.0
Either way Kargo verifies the artifact exists, resolves its transitive graph,
updates Kargo.toml and Kargo.lock, and leaves the rest of your manifest
formatting untouched. New entries are inserted in alphabetical order, so the
section does not drift as you add to it.
kargo add org.jetbrains.kotlin:kotlin-test:2.4.21 --dev # test-only
kargo add io.ktor:ktor-server-core:2.3.0 --target jvm # one target
kargo add com.example:ad-sdk:2.0.0 --flavor free # one flavor
The manifest key comes from the artifact id, which is a mouthful for the
platform-suffixed artifacts Kotlin Multiplatform publishes. --rename chooses
it:
kargo add io.ktor:ktor-server-core-jvm --rename ktor-server
[dependencies]
ktor-server = "io.ktor:ktor-server-core-jvm:3.6.2"
The key is a label — the coordinate in the value is what gets resolved — so
renaming one is safe at any time. Remember that kargo remove takes the key.
With --offline, a coordinate that omits its version is refused rather than
guessed at: the cache holds artifacts, not the list of what has been published
since. Name the version and the add works offline, because the manifest edit
itself needs no repository.
Removing
kargo remove kotlinx-coroutines-core
Takes the manifest key, not the coordinate. Mirror the flags you added with:
kargo remove kotlin-test --dev
kargo remove ktor-server-core --target jvm
The four places dependencies live
[dependencies] # every target, every variant
kotlinx-coroutines-core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"
[dev-dependencies] # test compilation and test runtime only
kotlin-test = "org.jetbrains.kotlin:kotlin-test:2.4.21"
[target.jvm.dependencies] # only when building the jvm target
ktor-server-netty = "io.ktor:ktor-server-netty:2.3.0"
[flavor.free.dependencies] # only in variants including the free flavor
ad-sdk = "com.example:ad-sdk:2.0.0"
A build sees [dependencies] plus the matching [target.*] and [flavor.*]
sections, with [dev-dependencies] added for test compilation. There is no
api versus implementation distinction: Kargo publishes a POM with
compile-scoped dependencies and relies on Kotlin's own visibility rules.
Specifying a dependency
Coordinate shorthand
kotlinx-coroutines-core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"
Detailed form
For anything shorthand cannot express:
[dependencies.my-lib]
group = "com.example"
artifact = "my-lib"
version = "1.0.0"
scope = "runtime" # compile (default), runtime, provided, test, system, import
optional = true # not propagated to consumers of your library
classifier = "linux-x86_64" # for artifacts with platform-specific builds
[[dependencies.my-lib.exclusions]]
group = "org.slf4j"
artifact = "slf4j-log4j12" # omit to exclude the whole group
| Scope | Available when |
|---|---|
compile | Compiling and running, and propagated to consumers. The default. |
runtime | Running only — not on the compile classpath. |
provided | Compiling only — expected to exist at runtime (servlet APIs, IDE plugins). |
test | Test compilation and test runtime. Equivalent to [dev-dependencies]. |
import | BOM import: pulls version constraints, no artifact. |
Catalog reference
kotlinx-coroutines-core = { catalog = "kotlinx-coroutines" }
ktor-server = { catalog = "ktor-server", bundle = true }
See Version Catalogs.
BOMs
Import a bill of materials to let it dictate versions for a family of artifacts:
[dependencies.ktor-bom]
group = "io.ktor"
artifact = "ktor-bom"
version = "2.3.0"
scope = "import"
[dependencies]
ktor-server-core = { group = "io.ktor", artifact = "ktor-server-core", version = "" }
An empty version means "take it from an imported BOM". If no BOM supplies one, resolution fails with the artifact named.
Repositories
Maven Central is configured by default. Add others by name:
[repositories]
google = "https://maven.google.com"
internal = { url = "https://nexus.example.com/repository/maven-releases", username = "${env:NEXUS_USER}", password = "${env:NEXUS_PASS}" }
sonatype-snapshots = { url = "https://oss.sonatype.org/content/repositories/snapshots" }
Repositories are tried in declaration order, Maven Central last. Credentials
should always come from .kargo.env via ${env:…} — never
literals in a committed manifest.
Shared credentials can live in global config instead and be referenced by name:
[repositories]
internal = { url = "https://nexus.example.com/maven", auth = "my-nexus" }
The lockfile
Kargo.lock records the exact resolved version, checksum, and source repository
of every artifact in the graph — direct and transitive.
[[package]]
name = "kotlinx-coroutines-core"
group = "org.jetbrains.kotlinx"
version = "1.8.0"
checksum = "sha256:…"
source = "https://repo.maven.apache.org/maven2"
A build with a lockfile resolves nothing: it reads versions, verifies checksums, and compiles. That makes builds reproducible and fast, and makes a dependency change visible in your diff.
kargo lock # regenerate from the manifest
kargo fetch # download everything in the lockfile without building
Should you commit the lockfile?
| Commit it | Why | |
|---|---|---|
| Applications | Yes | Everyone and every CI run builds the identical graph. |
| Libraries | Usually not | Your consumers resolve their own graph; your lock has no effect on them. Committing it only pins what your CI tests against — useful, but a choice. |
Updating
kargo update # all deps, within semver-compatible ranges
kargo update kotlinx-coroutines # one dependency
kargo update --major # allow major version bumps
kargo update --dry-run # show what would change
kargo update rewrites Kargo.lock, not Kargo.toml — your declared versions
stay put unless --major forces a manifest change.
To see what is available first:
kargo outdated
Package Current Compatible Latest
kotlinx-coroutines-core 1.8.0 1.8.1 1.9.0
ktor-server-core 2.3.0 2.3.12 3.0.1
--major includes the Latest column's breaking bumps in the update set.
Inspecting the graph
kargo tree
my-service v1.2.0
├── io.ktor:ktor-server-core v2.3.0
│ ├── io.ktor:ktor-http v2.3.0
│ └── org.jetbrains.kotlin:kotlin-stdlib v1.9.21
└── org.jetbrains.kotlinx:kotlinx-coroutines-core v1.8.0
└── org.jetbrains.kotlin:kotlin-stdlib v1.9.21 (*)
(*) marks a subtree already printed.
| Question | Command |
|---|---|
| Why is this in my build at all? | kargo tree --why kotlin-stdlib |
| What pulled in two versions of the same thing? | kargo tree --duplicates |
| Which versions conflicted, and who won? | kargo tree --conflicts |
| What licenses am I shipping? | kargo tree --licenses |
| Who depends on this? | kargo tree --inverted |
| Just the top level, please | kargo tree --depth 1 |
--why is the one to remember. It prints the path from your manifest to the
artifact, which is the answer to almost every "where did that come from"
question.
How conflicts resolve
When two paths require different versions of the same artifact, Kargo uses Maven's nearest-wins rule: the version declared closest to your project wins, ties broken by declaration order. This matches what Maven does — and differs from Gradle, which picks the highest version.
The practical consequence: if a transitive dependency needs a newer version than
the one that wins, declare it directly in [dependencies]. Depth zero beats
everything.
The Kotlin artifacts are the exception
Every org.jetbrains.kotlin artifact — kotlin-stdlib, -jdk7, -jdk8,
-reflect, kotlin-test — resolves to the kotlin version in [package],
whatever versions your dependencies ask for. They ship as one release and read
each other's internals, so a mix of two releases compiles cleanly and then
fails at startup with a ClassNotFoundException. Your compiler's own stdlib is
already on the classpath at that version, so this is the version that was going
to be used regardless.
org.jetbrains.kotlinx is not aligned: coroutines and serialization are
released on their own schedule and keep their own versions.
Being aligned is not the same as being on the classpath. The stdlib is there
without being declared, because the toolchain supplies it; kotlin-reflect is
not, so code calling into kotlin.reflect.full has to declare it. Match your
kotlin version when you do — a direct declaration wins over the alignment
above, and reflect from one release against a stdlib from another is the
startup failure this section is about.
To use a different version of one of them, declare it directly — a declaration in your manifest still wins:
[dependencies]
kotlin-reflect = "org.jetbrains.kotlin:kotlin-reflect:2.3.21"
kargo tree --conflicts # see every mediation decision
--conflicts reports an aligned artifact as aligned to package.kotlin, so
you can tell it from a lockfile pin or a nearest-wins decision.
Full detail in Dependency Resolution.
Offline builds
kargo fetch # populate the cache while you have a network
kargo build --offline # resolve only from ~/.kargo/cache
--offline fails rather than reaching the network, which makes it the honest way
to verify that a build is reproducible from cache — useful for air-gapped and
hermetic CI.
The cache is machine-wide, so one kargo fetch serves every checkout on the
machine: a second clone of the same project builds without downloading
anything. KARGO_HOME moves it along with everything else Kargo keeps, and
kargo cache stats reports its size.
A project's own .kargo/dependencies/ is still read if it is there, which is
how a CI cache restored into the workspace keeps working. Nothing is written
there any more.
Because the store is shared, no single project thins it out: a kargo fetch
that no longer needs an artifact leaves it where it is, since it is some other
checkout's dependency. kargo self clean empties it when you want the space
back.
Security
kargo audit
Checks the resolved graph against the OSV database. See Auditing Dependencies.
Next
- Version Catalogs — share versions across modules
- Auditing Dependencies — vulnerability scanning and policy
- Dependency Resolution — the algorithm in detail