Skip to content

Commit

Permalink
describe "explicit declaration" fix for Swift 5.2
Browse files Browse the repository at this point in the history
Added notes about fixing the "dependency requires explicit declaration" error when using recent versions of Swift Package Manager until swift-sh fixes its issue #111
  • Loading branch information
jpmhouston authored May 23, 2020
1 parent ccb955a commit 490f9bf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,38 @@ struct RenameMoviesCommand: ParsableCommand {

RenameMoviesCommand.main()
```

## Note for swift-sh 1.17.1 and recent versions of Swift Package Manager
Until swift-sh issue #111 https://github.com/mxcl/swift-sh/issues/111 is fixed and if you're using SPM from Swift 5.2 (Xcode 11.4 or later) then any script using RenameCommand will fail to build with a "dependency requires explicit declaration" error and output like this:

Updating https://github.com/jpmhouston/RenameCommand.git
Updating https://github.com/JohnSundell/Files
Updating https://github.com/sharplet/Regex.git
Updating https://github.com/apple/swift-argument-parser.git
Resolving https://github.com/jpmhouston/RenameCommand.git at 4c299aa2e4ff571893b18ac71aa39a195cb09bb1
'renametest' /Users/me/Library/Developer/swift-sh.cache/98d753591fe20951a239e2e2b1a6cc12: error: dependency 'ArgumentParser' in target 'renametest' requires explicit declaration; reference the package in the target dependency with '.product(name: "ArgumentParser", package: "swift-argument-parser")'
error: 1 <(/usr/bin/swift build -Xswiftc -suppress-warnings)

You'll need to copy the `swift-sh.cache` path out of that error and edit the file `Package.swift` in that directory, for example:

vi /Users/me/Library/Developer/swift-sh.cache/98d753591fe20951a239e2e2b1a6cc12/Package.swift

In `Package.swift` the occurance of `"ArgumentParser"` must be replaced with `.product(name: "ArgumentParser", package: "swift-argument-parser")`.

Explicitly, replace:

pkg.targets = [
.target(name: "rename-tv", dependencies: ["ArgumentParser", "RenameCommand", "Regex"], path: ".", sources: ["main.swift"])
]

with (I've expanded the inner array onto multiple lines):

pkg.targets = [
.target(name: "rename-tv", dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"RenameCommand",
"Regex"
], path: ".", sources: ["main.swift"])
]

Save this and build / run the script again and it should work. Unfortunately if any of those packages are updated in the future before swift-sh #111 is fixed you'll need to make this same edit again. You may want to explicitly fix the dependency versions in your `import` line comments to prevent this, see examples in the readme at https://github.com/mxcl/swift-sh.

0 comments on commit 490f9bf

Please sign in to comment.