Make Swift Package Builds Reproducible Across Machines

The same commit builds on one machine and fails on another because they resolved different dependency versions. Deleting both caches might make the failure disappear today, but it does not explain which graph you intended to build.

Make the selected dependency graph a reviewable input. Then tell the build to fail when that input is stale instead of silently choosing something else.

Requirements and resolution answer different questions

A Package.swift dependency requirement describes the versions the package permits. Package.resolved records the concrete result selected for that package graph. Swift’s PackageDescription documentation describes both and where the resolved file lives.

For a standalone executable package, keep its top-level Package.resolved with the application source. For Xcode-managed dependencies, inspect the resolved file associated with the actual project or workspace being built. A similarly named file elsewhere in the repository may belong to another graph.

Do not edit the resolved file by hand to make a conflict disappear. Resolve the intended requirements with the selected toolchain, inspect the resulting versions and revisions, and review that change with the code that needs it.

Enforce the saved graph

From a standalone package’s root, the relevant build command is:

swift build --force-resolved-versions

SwiftPM’s command documentation and the installed swift build --help describe this option as using only versions from the resolved file and failing when it is out of date. Confirm the flags supported by the toolchain your CI actually runs.

For this article, the existing OrderedSelection companion package built successfully with its saved resolution enforced. A disposable copy then changed its Swift Collections requirement while retaining the old resolved file. The enforced build rejected that inconsistent graph with an out-of-date resolved-file error, as intended.

Use a CI step appropriate to the project, preserving its existing workflow and path filters. This article does not require replacing an app’s CI system or changing its marketing version or build number.

Exact pins are not the only way to be deliberate

The small companion uses an exact dependency version to keep its demonstration stable. That is not a blanket recommendation to make every reusable library’s requirement exact.

Libraries participate in their consumers’ larger dependency graphs. Reasonable compatible version ranges can avoid unnecessary conflicts, while the top-level application records the selected graph it intends to ship.

A library’s own resolved file helps reproduce its development and test environment; it does not force every downstream application to adopt that entire graph. Keep those responsibilities distinct when reviewing a dependency update.

A cache is not a lockfile

A cache speeds retrieval or compilation. It should not be the only reason a build finds a particular revision. A clean checkout should have enough declared information to obtain the selected dependencies, subject to network access and repository availability.

Avoid routine cache deletion as the first response to every resolver problem. Compare the manifest, resolved graph, toolchain, package identity, mirrors, and local overrides first. A local path dependency or an edited checkout can explain why one developer sees code CI cannot see.

Record the selected Xcode path and Swift version alongside a failure. swift-tools-version describes package/tooling compatibility; it does not install or pin a particular compiler binary for every machine.

Define the level of reproducibility you need

A locked dependency graph is one layer. The SDK, compiler, build configuration, environment, generated inputs, plugins, and binary artifacts can still affect output. Matching package versions does not prove bit-for-bit identical application binaries.

For an ordinary app build, start with the practical promise: the same source commit, resolved dependencies, Xcode selection, and documented build command produce the expected product and pass its tests. Investigate stronger reproducibility requirements only when the project actually needs them.

September 2026 review: the companion’s enforced-resolution build passed with Xcode 27.0 and Swift 6.4. The deliberately stale resolution failed as expected; no cross-machine binary-identity claim is made.