Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update a single dependency with Swift Package Manager?

I have a local dependency in my Package.swift in the form of

.package(url: "file:///Users/User/Documents/.../my-dependency", .branch("master")),

The local dependency is under development. I wish to update to the latest version, but I cannot find a way to update only that package without having to pull and rebuild all the other project dependencies. So far I have to pull and rebuild Vapor and Fluent every time I make a small change to a local dependency (assuming I even have internet access).

When I run swift package update --help I see there is an instruction :

POSITIONAL ARGUMENTS:
packages        The packages to update (optional)

However, whenever I try something like swift package update my-dependency or swift package update My-Dependency, it does the same thing and re-pulls all.

How do I go about updating this single dependency? And assuming I eventually do want to update all my other third-party dependencies, how do I tell SPM to check if there is an actual change to the package on GitHub before re-pulling and rebuilding it?

like image 952
nubiquitous Avatar asked Jun 07 '20 06:06

nubiquitous


People also ask

How do I update Swift package dependencies?

To resolve, Open the project from the project panel, select the project (not the targets), then select the "Swift Packages" tab. Double click on the package you want to update and change the minimum version to the next major version.

Where are Swift package dependencies stored?

In order to cache the dependencies, they should be located in the project directory, but by default, SPM downloads the dependencies into the system folder: ~/Library/Developer/Xcode/DerivedData.

What is a package dependency in Swift?

A package dependency consists of a Git URL to the source of the package, and a requirement for the version of the package. The Swift Package Manager performs a process called dependency resolution to figure out the exact version of the package dependencies that an app or other Swift package can use.

How to update Swift dependencies in Xcode?

I just stumbled upon this question and found that the solution to "How to update swift dependencies in Xcode" has probably changed now that Swift Packages have been around for a few years. For me, the solutions was to simply go to File -> Swift Packages -> Update to Latest Package Versions. Show activity on this post.

How to change minimum version of a Swift Package?

To resolve, Open the project from the project panel, select the project (not the targets), then select the "Swift Packages" tab. Double click on the package you want to update and change the minimum version to the next major version. Show activity on this post.

Why are my packages not updating in Swift?

Many of the problems with packages not updating are because the swift package version rules limit the automatic package updates to the current major version only, i.e v3.3.1 of a package will update to v3.4.0, but will not update automatically to v4.0.1.


1 Answers

I found the solution :

.package(path: "path/to/dependency")

No need to run swift package update, it builds with the current local version. Also no need to commit the changes in the dependency each time.

See answer here by rounak

like image 130
nubiquitous Avatar answered Oct 02 '22 05:10

nubiquitous