How to Depend on a Pre-release Versions of Package with the Swift Package Manager


Overview

For example,

  • 2.0.0-beta.1 has a lower precedence than 2.0.0.
  • Set majorVersion: 2, then 2.0.0-beta.1 is not included.
  • Set majorVersion: 1, then 2.0.0-beta.1 is not included.
  • Set versions: Version(1,0,0)..<Version(2,0,0), then 2.0.0-beta.1 is included.
  • To specify 2.0.0-beta.1, set the following:
Version(2, 0, 0, prereleaseIdentifiers: [“beta”, “1”])

Note


Semantic Versioning

Swift packages are expected to follow Semantic Versioning.

Swift packages are expected to follow Semantic Versioning (SemVer), a standard for assigning version numbers to software releases.
https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageManagerCommunityProposal.md

Pre-release versions have a lower precedence than the associated normal version.

Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0–0.3.7, 1.0.0-x.7.z.92.
http://semver.org/

For example, 2.0.0-beta.1 has a lower precedence than 2.0.0.


Implementation

https://github.com/apple/swift-package-manager/blob/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a/Sources/PackageDescription/Package.swift#L30-L35
public class func Package(url url: String, versions: Range<Version>) -> Dependency {
return Dependency(url, versions)
}
public class func Package(url url: String, majorVersion: Int) -> Dependency {
return Dependency(url, Version(majorVersion, 0, 0)..<Version(majorVersion, .max, .max))
}

Set majorVersion: 2

2.0.0-beta.1 is not included.

Version(2, 0, 0)..<Version(2, .max, .max)

Set majorVersion: 1

2.0.0-beta.1 is not included.

Version(1, 0, 0)..<Version(1, .max, .max)

Set versions: Version(1,0,0)..<Version(2,0,0)

2.0.0-beta.1 is included.


Package.swift — The Manifest File

https://github.com/apple/swift-package-manager/blob/master/Documentation/Package.swift.md

Here’s an example of a Package.swift file to specify 2.0.0-beta.1:

import PackageDescription
let package = Package(
name: “TryKit”,
dependencies: [
.Package(url: “https://github.com/ikesyo/Himotoki.git",
Version(2, 0, 0, prereleaseIdentifiers: [“beta”, “1”]))
]
)

Run the following command on Terminal.app:

$ swift build

Himotoki-2.0.0-beta.1 is downloaded.

Cloning https://github.com/ikesyo/Himotoki.git
Resolved version: 2.0.0-beta.1