Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Package Manager - Resolve Package Versions terminal command

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.

like image 882
Cloud9999Strife Avatar asked Nov 14 '19 07:11

Cloud9999Strife


People also ask

How do I change the version of a Swift package?

You can also update every single Swift Package in your project at once. To do this, open the Files menu, navigate to Packages and then click Update to Latest Package Versions.

How do I update Swift package dependencies?

Right-click the package and select Update Package. You can also update all package dependencies to their latest versions by right-clicking Package Dependencies and selecting Update to Latest Package Versions OR by going to File → Packages → Update to Latest Package Versions.

What is Swiftpm package resolved?

The swift package resolve command resolves the dependencies, taking into account the current version restrictions in the Package. swift manifest and Package. resolved resolved versions file, and issuing an error if the graph cannot be resolved.


1 Answers

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

like image 175
vookimedlo Avatar answered Oct 16 '22 20:10

vookimedlo