18

I want to replace cocoapods with SPM. I have decided to go at it one library at a time. I removed the swinject library from cocoapods and added it via File->Swift Packages->Add Package Dependency

This was successful and the project built and ran as expected.

enter image description here

I then asked other people in my team to check out the branch and see if they can build the project on their side without issues. We then ran into the error "Missing package product 'Swinject'". We resolved this error by performing File->Swift Packages->Resolve Package Versions in Xcode.

I need to get this working on the build server as well. I tried typing in swift package --help in the Terminal app to see what commands are available. The resolve command looked promising so I tried that to no avail. (error: root manifest not found)

So, my question then, is there a terminal command that does the same as File->Swift Packages->Resolve Package Versions?

Note: When I added the 3rd party library via SPM, it created one file for me: Proj.xcworkspace/xcshareddata/swiftpm/Package.resolved. It also made various changes to the Proj.xcodeproj/project.pbxproj file. No package.swift file was created.

Update: The closest I have gotten to an answer was that I should try xcodebuild -resolvePackageDependencies, unfortunately the command does not do the same as File->Swift Packages->Resolve Package Versions.

1
  • If someone is passing by and still have problems with their CI, you could also check that you didn't ignore the schemes located in .swiftpm/xcode/ folders
    – itMaxence
    Feb 12, 2021 at 1:47

2 Answers 2

23
+200

I was struggling with the SPM in my project. It seems that you need to pass the -clonedSourcePackagesDirPath [directory]

xcodebuild -resolvePackageDependencies -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .

xcodebuild -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .

The first command resolves and downloads all Swift Packages into the ./checkouts and some other ./[dirs] are also created.

The second command initiates the build of your application, and those SPM packages are also built.

Here is output from the build server: https://travis-ci.org/vookimedlo/ck550-macos/builds/626438212

Travis-CI configuration: https://github.com/vookimedlo/ck550-macos/blob/master/.travis.yml

1
  • THX! This is works for me on Azure Pipeline. My project contains only SPM and only opensource (Vapor) packages from Github!
    – feca
    May 5, 2020 at 19:44
7

From what I have seen, there are 2 Package.resolved files. One on the workspace and one on the project. For some reason the workspace has old versions of the packages and running

xcodebuild -resolvePackageDependencies -workspace myworkspace.xcworkspace -scheme my scheme

does not work. However, resolving on the project (since the project's Package.resolved has the correct packages version info) does work

xcodebuild -resolvePackageDependencies -project myproject.xcodeproj -scheme my scheme
1
  • 2
    Fantastic help - I was totally stuck with Xcode 13.2.1 not being able to resolve the packages (don't get me started on Apple quality...)
    – David H
    Mar 1, 2022 at 21:47

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.