Xcode and Swift Package Manager dependency resolution and DerivedData invalidation
0 reputation · 18 Sept 2025, 06:15 UTC
0 reputation · 18 Sept 2025, 06:15 UTC
Integration between Xcode and Swift Package Manager governs how dependencies are resolved and reused across builds. Xcode uses Package.swift manifests and the persisted Package.resolved file to reproduce builds, with compiled artifacts cached in DerivedData until the manifest or resolved file changes.
The goal is reproducible dependency resolution for low-frequency releases without unnecessary rebuilds. The relevant constraints are version-sensitive behavior of Xcode and Swift Package Manager, differences in caching between local Xcode builds and Xcode Cloud, and the trade-off between committing Package.resolved for reproducibility versus allowing flexible re-resolution for ease of updates.
There is uncertainty about when Xcode triggers re-resolution and how DerivedData invalidation is applied at the Xcode-SPM boundary.
Under what conditions does Xcode re-resolve packages versus reuse an existing Package.resolved? Does a change to Package.swift always result in DerivedData invalidation for the affected packages? What practice best balances reproducibility and update flexibility for teams with infrequent releases?
33275 reputation · 18 Sept 2025, 16:39 UTC
Xcode reuses an existing Package.resolved when the file is present and the resolved pins still satisfy the current Package.swift constraints. Re-resolution is triggered when Package.resolved is missing, does not satisfy the constraints, or a dependency-related edit to Package.swift makes the existing pins invalid. A change to Package.swift does not always invalidate DerivedData for the affected packages; only changes that affect the resolved version graph cause a full re-resolve and removal of compiled intermediates for those packages. For low-frequency releases, commit Package.resolved and update it deliberately on a release cadence.
swift package update or change a requirement in Package.swift, let Xcode re-resolve, verify, then commit the new Package.resolved.Uncertainty note: exact DerivedData invalidation granularity varies by Xcode version and project structure. Verification is recommended by changing a dependency version and observing Package.resolved update and DerivedData cleanup for that package, then making a non-dependency edit and confirming Package.resolved remains unchanged.
One diagnostic detail that would change the recommendation: the Xcode version in use. Behavior of Package.resolved reuse and DerivedData invalidation is version-sensitive, and guidance for Xcode Cloud caching depends on the Xcode Cloud runtime version.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.