如何为蒸汽添加新的依赖项?

Posted

技术标签:

【中文标题】如何为蒸汽添加新的依赖项?【英文标题】:how to add a new dependency to vapor? 【发布时间】:2021-12-31 12:53:45 【问题描述】:

我想向 vapor 中添加一个新的依赖项,但出现此错误 - 目标“App”的依赖项中的未知包“Web3”;有效的包是:'vapor'、'fluent'、'fluent-postgres-driver'、'jwt'、'Web3.swift'

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "w3-wallet-backend",
    platforms: [
        .macOS(.v10_15)
    ],
    dependencies: [
        // ???? A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),

        // ???? Authentication and Authorization framework for Fluent.
        .package(url: "https://github.com/vapor/jwt.git", from: "4.0.0"),
        
        // ???? blockhain Swift framework.
        .package(url: "https://github.com/Boilertalk/Web3.swift.git", from: "0.5.0"),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Fluent", package: "fluent"),
                .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
                .product(name: "Vapor", package: "vapor"),
                .product(name: "JWT", package: "jwt"),
                .product(name: "Web3", package: "Web3"),
                .product(name: "Web3PromiseKit", package: "Web3"),
                .product(name: "Web3ContractABI", package: "Web3")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .executableTarget(name: "Run", dependencies: [.target(name: "App")]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

【问题讨论】:

【参考方案1】:

包名称等于它的存储库名称,所以在你的情况下它应该是

.product(name: "Web3", package: "Web3.swift"),
.product(name: "Web3PromiseKit", package: "Web3.swift"),
.product(name: "Web3ContractABI", package: "Web3.swift")

【讨论】:

以上是关于如何为蒸汽添加新的依赖项?的主要内容,如果未能解决你的问题,请参考以下文章

Maven - 如何为休眠添加所有必需的依赖项?

leiningen - 如何为本地 jar 添加依赖项?

如何为依赖目标添加 cmake 定义?

如何为项目/lib 中的本地 jar 创建 Ivy 依赖项?

如何为箭头包安装 C++ 依赖项?

有啥建议如何为像 Visual Studio 2010 测试这样的 NUnit 测试部署依赖项吗?