Force installing oldest supported version of a dependency?

As I understand it the reason to use from: "version" is to enable better compatibility with other packages in the same dependency graph. A good example of this would be setting the minimum version of swift-syntax when providing a macro.

When developing locally and running tests in CI the Package.resolved file will be used, but this will usually have the latest version of the dependency (or something newer than the version in the Package.swift file).

Is there a (simple) way to have SwiftPM install the oldest supported version of a dependency so I can validate that the from value is correct? This would be useful locally but may be crucial in CI.

Removing the Package.resolved file and replacing from: "version" with exact: "version" is one way to do this, but it would be nice if there were a more automated/official way of doing this.

1 Like

I'm not sure if there is any kind of direct ability to manipulate a package in this way.

A legit workaround might be to define an environment variable from shell before you begin your build. Your package manifest could then add conditional logic off the state of that variable to pick an exact version of the dependency you are trying to test against.

I may look in to this, but I am hoping there's a solution that doesn't require extra maintenance or complications of the Package.swift file.

I looked at the tools we currently have access to. I think this will be possibly by parsing the output of swift package dump-package and then running swift package resolve with the lowerBound of each dependency. At least this doesn't modify the Package.swift file and relies on swift itself to do the resolving and updating of Package.resolved.