I want to programmatically update the versions of Swift Packages consumed by a sample project.
Xcode > 11 offers a menu option:
File > Swift Packages > Update to Latest Package Versions
This will update the Package.resolved
file to point to a specific revision.
This file is located at:
MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
How can I trigger this action from the command line for a CI build?
Try out xcodebuild -resolvePackageDependencies
xcodebuild -resolvePackageDependencies
does not seem to work reliably. It will often stubbornly refuse to update to the latest version, particularly when an SPM dependency is pointed to a branch rather than a version tag. Obviously Xcode is caching this information somewhere, but I could not figure out exactly which file it is. Even nuking the SourcePackages
folder in the derived data did not do the trick.
The only way I have found to do this reliably is to nuke the entire DerivedData
subfolder for the Xcode project.
derived=$(xcodebuild -showBuildSettings | grep -m 1 BUILD_DIR | grep -oE "\/.*" | sed 's|/Build/Products||')
# The above will return a folder with a name like /Users/you/Library/Developer/Xcode/DerivedData/MyProject-ehdkocavaenextdcrsaszjdmyssx
rm -rf "$derived"
xcodebuild -resolvePackageDependencies
It is completely safe to delete the DerivedData subfolder for a project. Xcode will simply regenerate it on demand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With