I want to include the SPMUtility library of the Swift Package Manager (SPM) project as a dependency to my project "ngfz
". In doing this, I encounter several problems.
First and foremost, how to I see the list of available semver versions of the SPM project to specify in:
...
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0"),
]
...
I cannot find this information on the Github page?
Secondly, the SPM documentation says that I should specify a product dependency for my target, optionally including the package name:
.target(
name: "ngfz",
dependencies: [
.product(name: "SPMUtility", package: "SwiftPM")
]),
However, results in the following error:
swift build --product nfgz
'ngfz' /Users/nlykkei/Projects/ngfz: **error:** product dependency 'SPMUtility' in package 'SwiftPM' not found
If I instead remove package: "SwiftPM"
from the .target
above, then everything works fine, and the dependencies display as follows:
swift package show-dependencies
.
āāā SwiftPM<https://github.com/apple/swift-package-manager.git@0.4.0>
āāā llbuild<https://github.com/apple/swift-llbuild.git@0.1.1>
So, why can't I specify .product(name: "SPMUtility", package: "SwiftPM")
in the .target
?
I hope to get the following answered:
- How do I see the available semver versions of the SPM project to specify in
from: "0.3.0"
? - How do I specify the package dependency in
.product(name: "SPMUtility", package: "SwiftPM")
?
The complete (and working) Package.swift file:
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ngfz",
products: [
.executable(
name: "ngfz",
targets: ["ngfz"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "ngfz",
dependencies: [
.product(name: "SPMUtility")
]),
.testTarget(
name: "ngfzTests",
dependencies: ["ngfz"]),
]
)