Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use SwiftPM as a dependency using Swift Package Manager?

I have the following Package.swift:

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "my-vapor-project",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/apple/swift-package-manager", .branch("master")),
    ],
    targets: [
        .target(name: "App", dependencies: [
            .product(name: "Fluent", package: "fluent"),
            .product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
            .product(name: "Vapor", package: "vapor"),
            .product(name: "SwiftPM", package: "swift-package-manager")
        ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

When I save the file, Xcode attempts to resolve the dependencies automatically, and I get the following error and warning:

Showing All Messages /Users/sluther/Projects/my-vapor-project/Package.swift: product dependency 'SwiftPM' in package 'swift-package-manager' not found

: dependency 'SwiftPM' is not used by any target

like image 321
sluther Avatar asked Mar 03 '23 15:03

sluther


1 Answers

It turns out that at the time of writing, Swift Package Manager could not be included as a dependency when using Swift Tools Version 5.2 which removed the old syntax for defining Product dependencies. Switching the Swift Tools Version to 5.1 resolved the issue.

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "my-vapor-project",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/apple/swift-package-manager", .branch("master")),
    ],
    targets: [
        .target(name: "App", dependencies: [
            .product(name: "Fluent", package: "fluent"),
            .product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
            .product(name: "Vapor", package: "vapor"),
            "SwiftPM"
        ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)
like image 115
sluther Avatar answered Mar 05 '23 16:03

sluther