Closed
Description
Is it reproducible with SwiftPM command-line tools: swift build
, swift test
, swift package
etc?
- Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands,
swift build
,swift test
,swift package
etc.
Description
If you invoke swift package add-dependency
twice, the dependency is added to the package.swift file twice, rendering the project unbuildable.
Expected behavior
If the dependency already exists, the add-dependency command should either return an error or warning that the dependency already exists.
Actual behavior
The dependency is added twice, with identical configurations. The resulting Package.swift isn't valid to build a project.
Steps to reproduce
mkdir DepExample
cd DepExample
swift package init
swift package add-dependency https://github.com/apple/swift-docc-plugin --from 1.1.0
This project is buildable: swift build
:
Fetching https://github.com/apple/swift-docc-plugin from cache
Fetched https://github.com/apple/swift-docc-plugin from cache (0.31s)
Computing version for https://github.com/apple/swift-docc-plugin
Computed https://github.com/apple/swift-docc-plugin at 1.4.4 (0.81s)
Fetching https://github.com/swiftlang/swift-docc-symbolkit from cache
Fetched https://github.com/swiftlang/swift-docc-symbolkit from cache (0.35s)
Computing version for https://github.com/swiftlang/swift-docc-symbolkit
Computed https://github.com/swiftlang/swift-docc-symbolkit at 1.0.0 (0.77s)
Creating working copy for https://github.com/apple/swift-docc-plugin
Working copy of https://github.com/apple/swift-docc-plugin resolved at 1.4.4
Creating working copy for https://github.com/swiftlang/swift-docc-symbolkit
Working copy of https://github.com/swiftlang/swift-docc-symbolkit resolved at 1.0.0
[1/1] Planning build
Building for debugging...
[3/3] Write swift-version--44D72886A502174.txt
Build complete! (8.06s)
Add the dependency again:
swift package add-dependency https://github.com/apple/swift-docc-plugin --from 1.1.0
No error is reported, and the Package.swift is updated... And the project no longer builds swift build
:
error: 'depexample': 'depexample' dependency on 'https://github.com/apple/swift-docc-plugin' conflicts with dependency on 'https://github.com/apple/swift-docc-plugin' which has the same identity 'swift-docc-plugin'
error: ExitCode(rawValue: 1)
[0/1] Planning build
Swift Package Manager version/commit hash
6.1.2
Swift & OS version (output of swift --version ; uname -a
)
swift --version
:
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
uname -a
:
Darwin Joes-MacBook-Pro-3.local 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041 arm64