我使用Swift软件包管理器来管理我的项目中的依赖项。我正试图在我的快速包中导入LineNoise,但我得到了以下信息:
nathanfallet:SwiftMC nathanfallet$ swift run
Fetching https://github.com/andybest/linenoise-swift.git
Fetching https://github.com/Quick/Nimble.git
Fetching https://github.com/apple/swift-argument-parser
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/adam-fowler/compress-nio.git
Cloning https://github.com/apple/swift-nio.git
Resolving https://github.com/apple/swift-nio.git at 2.17.0
Cloning https://github.com/adam-fowler/compress-nio.git
Resolving https://github.com/adam-fowler/compress-nio.git at 0.3.0
Cloning https://github.com/apple/swift-argument-parser
Resolving https://github.com/apple/swift-argument-parser at 0.0.6
Cloning https://github.com/andybest/linenoise-swift.git
Resolving https://github.com/andybest/linenoise-swift.git at 0.0.3
Cloning https://github.com/Quick/Nimble.git
Resolving https://github.com/Quick/Nimble.git at 7.3.4
'SwiftMC' /Users/nathanfallet/git/SwiftMC: error: product dependency 'LineNoise' in package 'linenoise-swift' not found这不是我导入的第一个包,其他程序也在工作(我也是以同样的方式导入它们)。我和其他包一样将这个包添加到我的Package.swift文件中,但是这个包似乎不起作用.
我的Package.swift文件:
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SwiftMC",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftMC",
targets: ["SwiftMC"]),
.executable(
name: "SwiftMCRun",
targets: ["SwiftMCRun"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "0.0.1"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.0.1"),
.package(url: "https://github.com/andybest/linenoise-swift.git", from: "0.0.1")
],
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: "SwiftMC",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "CompressNIO", package: "compress-nio")
]),
.target(
name: "SwiftMCRun",
dependencies: [
"SwiftMC",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "LineNoise", package: "linenoise-swift") // Error seems to come from here; I tried "linenoise", "LineNoise", "linenoise-swift" but nothing seems to work
]),
.testTarget(
name: "SwiftMCTests",
dependencies: ["SwiftMC"]),
]
)知道这是怎么回事吗?为什么这个包没有进口,而其他人呢?
发布于 2021-05-31 11:58:38
原因:
当包指定与github回购名称不同的Package.name属性时,会发生此问题。例如,LineNoise的回购名称是linenoise-swift,但LineNoise。您将注意到所有其他依赖项都有与package.swift包名称一致的github名称。
Fix:只是.package的包名
要解决这个问题,请在您的中显式地指定包依赖项的包名(您可以在库package.swift文件中找到该名称)。
// Latest prerelease
.package(name: "LineNoise", url: "https://github.com/andybest/linenoise-swift", from: "0.0.3")现在,在目标依赖项中,可以使用LineNoise作为package参数。
另一个例子(Mapbox导航):
在使用MapBox导航库时,我遇到了类似的问题。而不是像我添加其他库那样使用添加,而是声明使用特定用途的文档
要在另一个包而不是应用程序中安装MapboxNavigation框架,请运行
swift package init来创建Package.swift,然后添加以下依赖项:
// Latest prerelease
.package(name: "MapboxNavigation", url: "https://github.com/mapbox/mapbox-navigation-ios.git", .exact("2.0.0-beta.11"))无论如何,看起来您的存储库不再使用lineNoise了。
对包开发人员的注意:
确保您的GitHub回购是相同的名称与您的包名,它将只是更方便。
https://stackoverflow.com/questions/61837852
复制相似问题