如何在没有 git 存储库的情况下使用本地 SPM 包?

How do I use a local SPM package without a git repository?

关于 Swift 包管理器,如何在没有 git 存储库的情况下将本地库包用作可执行包的依赖项? SwiftPM 声称它允许您在 url 字段中传入本地路径,但随后抱怨它无法克隆存储库。

来自 Package.swift

    dependencies: [
    // Dependencies declare other packages that this package depends on.
    .package(url: "../../../string-calculator/swift/StringCalculator", from: "1.0.0"),
],

当 运行 swift package update 我得到以下输出:

Fetching /Users/tsd037/Documents/Workspace/Misc/tdd-kata/string-calculator/swift/StringCalculator
error: failed to clone; fatal: repository '/Users/tsd037/Documents/Workspace/Misc/tdd-kata/string-calculator/swift/StringCalculator' does not exist

请注意,即使对于本地目录,您也必须创建一个 git 存储库(本地)。只需在本地目录中 运行 git init git commit 并添加标签,例如git tag 1.0.0.

遇到了同样的问题,在API文档中找到了以下解决方案。

https://developer.apple.com/documentation/swift_packages/package/3583304-init https://developer.apple.com/documentation/swift_packages/package/dependency/3582846-package

使用“路径”参数代替“url”

 dependencies: [
    // Dependencies declare other packages that this package depends on.
    .package(path: "../../../string-calculator/swift/StringCalculator"),
],