0Pricing
Swift Academy · Lesson

Versioning, Resolving Conflicts and Swift Plugins

Managing version ranges, resolving dependency conflicts and using build tool plugins.

Versioning, Resolving Conflicts and Swift Plugins is a free Swift Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Semantic Versioning in SPM

SPM uses semver: MAJOR.MINOR.PATCH. Declare requirements with from:, exact:, or .upToNextMajor.

.package(url: "https://github.com/apple/swift-log", from: "1.5.0"),
.package(url: "https://github.com/vapor/vapor", exact: "4.83.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture",
  .upToNextMajor(from: "1.0.0"))

Package.resolved

Package.resolved pins exact versions for all dependencies. Commit it for apps; omit it for libraries.

// Package.resolved (auto-generated):
// Pins exact commit hash and version for every dependency
// Run "swift package update" to update pinned versions

Resolving Version Conflicts

When two packages require different versions of the same dependency, SPM tries to find a compatible version. Conflicts that cannot be resolved cause a build error.

// PackageA requires Logging 1.4.0
// PackageB requires Logging 1.5.0
// SPM resolves to 1.5.0 (satisfies both >= 1.x)
// Conflict: PackageA requires Logging 1.x, PackageB requires 2.x

Forcing a Version

Add the conflicting dependency directly to your app's Package.swift to override the version that SPM would otherwise choose.

// Force Logging 1.5.0 by declaring it directly:
.package(url: "https://github.com/apple/swift-log", exact: "1.5.0")

Build Tool Plugins

Build tool plugins run during the build to generate source code, process resources, or run linters automatically.

// In Package.swift:
.plugin(
  name: "SourceGenerator",
  capability: .buildTool()
)

Implementing a Build Tool Plugin

A build tool plugin conforms to BuildToolPlugin and returns BuildCommands or PrebuildCommands.

import PackagePlugin

@main
struct SourceGenerator: BuildToolPlugin {
  func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
    let output = context.pluginWorkDirectory.appending("Generated.swift")
    return [.buildCommand(
      displayName: "Generating sources",
      executable: try context.tool(named: "gen-tool").path,
      arguments: ["--output", output],
      outputFiles: [output]
    )]
  }
}

Command Plugins

Command plugins run on demand from Xcode or the CLI, useful for formatting, linting, or generating documentation.

// In Package.swift:
.plugin(
  name: "FormatPlugin",
  capability: .command(intent: .sourceCodeFormatting())
)

Running a Command Plugin

Execute command plugins from the terminal or Xcode right-click menu.

// CLI:
swift package plugin format-source-code
// Xcode: right-click target → "Format Source Code"

Using SwiftLint as a Build Plugin

SwiftLint ships as an SPM plugin that runs automatically on every build.

.package(url: "https://github.com/realm/SwiftLint", from: "0.54.0"),
// In target:
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")

Plugin Sandbox

Plugins run in a sandbox with limited file system access for security. They can only write to their designated work directory.

// Accessible from plugins:
// context.pluginWorkDirectory — writable work dir
// context.package.directory — read-only source
// target.sourceFiles — source file list

Quick Check

What is the purpose of Package.resolved in a Swift package?

Lesson Recap

Use semver ranges in Package.swift. Commit Package.resolved for apps for reproducible builds. Resolve version conflicts by declaring the dependency directly. Build tool plugins auto-run during build (linters, code generators). Command plugins run on demand. Plugins are sandboxed for security.

Frequently asked questions

Is the “Versioning, Resolving Conflicts and Swift Plugins” lesson free?

Yes — the full text of “Versioning, Resolving Conflicts and Swift Plugins” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Versioning, Resolving Conflicts and Swift Plugins”?

Managing version ranges, resolving dependency conflicts and using build tool plugins. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Versioning, Resolving Conflicts and Swift Plugins” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Package.swift: Targets, Products and Dependencies
  2. Local Packages and Feature Modules
  3. Binary Targets and XCFrameworks
  4. Versioning, Resolving Conflicts and Swift Plugins
← Back to Swift Academy