iosswiftxcodeswift-package-manager

Sharing a Swift Package amongst other Swift Packages


I'm new to creating Swift Packages, and I've hit a roadblock. I have 3 packages, A, B, and C. A depends on B, and C depends on B. I also have a SwiftUI app, and It needs to depend on packages A and C. I can add a dependency on one of the packages, say A, but then when adding the next package, I get unexpected errors. I imagine it has something to do with packages A and C sharing a dependency.

Can I accomplish what I want, or is this not currently possible with SwiftPM? How do other developers accomplish having a core package with a series of other packages that depend on the shared core?

The error I get in the app when adding dependency C is:

Failed to resolve dependencies Dependencies could not be resolved because root depends on 'Package A' 1.0.1..<2.0.0 and root depends on 'Package C' 2.0.1..<3.0.0


Solution

  • Both A and B list package C as their dependency, but they require different version ranges, with no overlap.

    There's no version of C that can be picked to meet A and B's version requirements at the same time, so SPM can't proceed. E.g. C v2.0.0 is too new for package A, and tool old for package B.

    You need to change the ranges to have a common overlap. Ideally, they should require the same versions, if these are in the same project.