swiftxcodedependenciesswift-package-manager

Nested SPM dependency version management


Let SDK_A a SDK depending on SDK_B, an other S, both published on SPM. SDK_A defines dependency to SDK_B using the from: Version(M, m, p) form.

How does an Application integrating SDK_A can force a version of SDK_B?


Example: SDK_A version 1.2.4 is available, same for SDK_B. Every version of SDK_A dependent on SDK_B from(1, 0, 0).

How can I integrate SDK_A version 1.2.2 AND force SDK_B to also be integrated as version 1.2.2 instead of 1.2.4 like defined in SDK_A package?


Solution

  • Since you can only have the same version of each dependency, a solution would be to force your main app to have that dependency (only if it's really needed through a subdependency) to that particular version:

    You currently have:

    Main App 
    -> Framework A
        -> Framework B
    

    Let's do this:

    Main App 
    -> Framework A
        -> Framework B
    -> Framework B at specific version (still compatible with Framework A version)
    

    That way, Framework A will check: Do I need to download for myself Framework B? Oh, It's already there (since it's specified at the same level as myself), are the versions compatible between my needs and the added one? Yes? Let's use that one then.