Dependency resolution

On this page 7

Dependency resolution is the process in which a package manager computes a consistent set of package versions that satisfies every requirement declared by a program and by all the packages it depends on. In software installation & packages, it is the step that turns a short list of direct requirements into a complete, installable dependency tree.

The task sounds mechanical, yet it is one of the hardest problems a package manager solves. Each package states version constraints for its own dependencies, those dependencies state constraints of their own, and the resolver must find one version per package (or an allowed set of versions) so that no constraint is violated. When no such combination exists, the resolver must report a conflict clearly enough for a developer to fix it.

How a resolver builds the dependency graph

A resolver starts from the root requirements in a package manifest, such as requests>=2.28 or react ^18.2.0, and queries the package registry for the available versions and their metadata. Each candidate version contributes its own list of requirements, so the resolver expands the problem step by step into a directed graph of packages and constraints.

At each step, the resolver chooses a candidate version, adds its requirements to the open set and checks whether every constraint collected so far can still be met. If a later requirement contradicts an earlier choice, the resolver must backtrack, discard that choice and try another version. This search continues until every package has a selected version or every alternative is exhausted.

Formally, dependency resolution with arbitrary version constraints is NP-complete, because it can encode Boolean satisfiability. In practice, registries are structured enough that good heuristics solve most real projects in seconds, although pathological cases with many overlapping constraints can still take minutes or fail to finish.

The table below lists the main inputs a resolver uses and how each one shapes the result.

InputExampleEffect on the result
Version constraint>=1.4,<2.0Narrows the allowed versions
Platform markerWindows only, Python 3.11Includes or excludes a dependency
Optional featureExtras or feature flagsAdds dependencies on request
Lock fileExact pinned versionsReuses a previous solution
Registry indexPublished versions and metadataDefines the candidate pool
Resolution strategyNewest or oldest compatibleChooses among valid solutions
Inputs to dependency resolution

Resolution algorithms and strategies

Package managers use different algorithms, and the choice determines speed, the quality of error messages and whether duplicate versions are allowed. Ecosystems that permit several versions of one package side by side face an easier problem than ecosystems that require a single version per package.

The following comparison shows the main approaches and where they appear.

ApproachHow it worksTypical trade-off
Backtracking searchTries versions, undoes choices on conflictSimple, can be slow on hard cases
SAT solverEncodes constraints as Boolean clausesComplete, but errors are hard to read
PubGrubConflict-driven learning with explanationsFast, with clear conflict reports
Minimal version selectionPicks the lowest version that satisfies allPredictable, no solver search needed
Nested installationEach package gets its own dependency copyAvoids conflicts, increases disk use
Common resolution approaches

Linux distribution tools such as those built on libsolv rely on SAT solving, while several modern language package managers adopted PubGrub-style resolution for its explanations. The Go module system uses minimal version selection, which trades automatic upgrades for highly reproducible builds.

Dependency resolution is the computation itself, and several neighboring terms describe its inputs, outputs or failures. Keeping them apart helps when diagnosing installation problems.

This table maps the related concepts to their role in the process.

ConceptRole in resolutionRelationship
Package manifestDeclares direct requirementsInput
Transitive dependencyRequirement of a requirementPart of the search space
Peer dependencyMust be supplied by the host projectSpecial constraint
Dependency treeFinal selected graphOutput
Dependency lock fileRecords the exact solutionSaved output, reusable input
Dependency hellNo workable solution, or a fragile oneFailure mode
Where related concepts fit

A lock file separates resolution from installation. Resolution runs when requirements change, the result is written to the lock file, and later installs simply reproduce it. This is why continuous integration builds should install from the lock file rather than resolve afresh.

Controlling resolution in practice

Developers influence the resolver mainly through how tightly they write constraints. Ranges that are too narrow cause conflicts, while ranges that are too broad admit untested versions. Semantic versioning makes ranges meaningful, because a major version change signals a breaking change.

The decision table below gives practical guidance for common situations.

SituationRecommended practiceReason
Publishing a libraryBroad compatible rangesLeaves room for other packages
Deploying an applicationCommit a lock fileGuarantees reproducible installs
Security fix in a transitive packageOverride or constraint fileForces a safe version
Unresolvable conflictRead the conflict chain, relax one boundTargets the actual cause
Slow resolutionAdd lower bounds to old packagesPrunes the search space
Choosing a constraint strategy

Version pinning in libraries is a common mistake: a library that pins exact versions forces every consuming project into the same versions and multiplies conflicts. Applications pin, libraries declare ranges is the widely accepted rule of thumb.

Failure modes and common mistakes

Resolution failures fall into a few recognizable patterns, and most of them stem from incompatible upper bounds or inconsistent registry metadata rather than from resolver bugs.

  • Diamond conflict: two packages require incompatible versions of the same shared dependency.
  • Overly strict upper bounds block valid upgrades long after the risk has passed.
  • Yanked or deleted versions break lock files that reference them.
  • Dependency confusion: a resolver prefers a malicious public package over a private one with the same name.
  • Silent drift: resolving without a lock file installs different versions on different machines.

Dependency confusion is a security risk, not only a correctness issue. Configuring scoped registries or explicit index priorities ensures that internal package names are never resolved from a public source.

The idea in brief

Imagine planning a dinner party where every guest brings friends, and some of those friends refuse to sit with certain others. Dependency resolution is the job of finding a seating plan that keeps everyone satisfied.

A program asks for a few building blocks, and each block needs other blocks in particular versions. The package manager works through all those wishes and picks one version of each block that fits together. When no combination works, it reports a conflict so that a person can change a requirement.

A practical scenario

A backend team adds a new reporting library to a Python web service. The library requires a data-processing package at version 2.x, while an existing analytics module still demands version 1.x. Running the installer produces a clear conflict report showing both requirement chains.

The team checks the analytics module’s changelog, finds that its latest release supports version 2.x and raises its minimum version in the manifest. The resolver now finds a consistent set of 48 packages in a few seconds, and the team commits the updated lock file. Every developer machine and the production build install identical versions, and the new reports ship in the next release without further breakage.