How to Beautify Swift Package Resolution in VSCode
Formatted Swift Package resolution for VSCode, Cursor, and Windsurf using xcodebuild with xcbeautify.
Swift extensions in VSCode-based IDEs (VSCode, Cursor, Windsurf) resolve packages with noisy, hard-to-scan logs. For Xcode projects (.xcodeproj
/.xcworkspace
), you can use xcodebuild -resolvePackageDependencies
and pipe to xcbeautify
for readable output. You can also automate this process. Here is how:
Step 1: Install xcbeautify
1
brew install xcbeautify
Step 2: Add a VSCode Task
Create .vscode/tasks.json
at the project root:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"version": "2.0.0",
"tasks": [
{
"label": "Resolve Package Dependencies",
"type": "shell",
"command": "set -o pipefail && xcodebuild -resolvePackageDependencies | xcbeautify",
"problemMatcher": [],
"presentation": {
"clear": true,
"showReuseMessage": false,
"reveal": "always",
"panel": "shared",
"close": true
}
}
]
}
Step 3: Run the Task
Press Cmd+Shift+P → Tasks: Run Task → Resolve Package Dependencies.
Command Breakdown
- Basic resolution
1
xcodebuild -resolvePackageDependencies
- With formatted output
1
xcodebuild -resolvePackageDependencies | xcbeautify
- CI-friendly exit codes (propagate failures across the pipe)
1
set -o pipefail && xcodebuild -resolvePackageDependencies | xcbeautify
Optional: Specify Scheme
Add a scheme if your workspace requires it:
1
xcodebuild -resolvePackageDependencies -scheme "MyApp" | xcbeautify
Usually xcodebuild
infers the right target; add -scheme
only if it cannot.
If the Task Never Finishes
- Ensure the task completes when the command exits by adding an empty matcher:
1
"problemMatcher": []
- If
xcodebuild
itself stalls, bypass the SPM repo cache:
1
"command": "set -o pipefail && xcodebuild -resolvePackageDependencies -disablePackageRepositoryCache | xcbeautify"
Alternatives to xcbeautify
xcbeautify
is fast and handles the modern build system well, but you can use any formatter that parses xcodebuild
output:
1
2
3
xcodebuild -resolvePackageDependencies | xcpretty # legacy
# or
xcodebuild -resolvePackageDependencies | your-custom-formatter
Why This Works
xcodebuild
does the real work (downloading and resolving packages). xcbeautify
only formats the logs for readability. For pure Swift packages (no Xcode project/workspace), swift package resolve
is fine; for Xcode projects, prefer xcodebuild -resolvePackageDependencies
.
Optional: Auto-close Terminal on Success
The VSCode setting "presentation.close": true
closes the task panel only on success and keeps it open on failure so you can read errors. This is the default behavior of close
when set to true
.
- Success (exit code 0): panel closes automatically
- Failure (non‑zero exit code): panel stays open for debugging
Combining that with set -o pipefail
ensures the terminal closes only when the whole pipeline succeeds (including xcbeautify
).
Quick Reference
1
2
3
4
5
6
7
8
9
10
11
# Install formatter
brew install xcbeautify
# Resolve with readable output
set -o pipefail && xcodebuild -resolvePackageDependencies | xcbeautify
# Add -scheme only if inference fails
xcodebuild -resolvePackageDependencies -scheme "MyApp" | xcbeautify
# Workaround for hangs
xcodebuild -resolvePackageDependencies -disablePackageRepositoryCache | xcbeautify
☕ Support My Work
If you found this post helpful and want to support more content like this, you can buy me a coffee!
Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏