Skip to main content

Swift CLI Usage

This page describes the CLI commands to resolve and build, publish and download packages after creating and configuring a Swift repository on Nexus.

Resolve and Build Swift Packages

To resolve and build the Swift packages, take the following steps:

  1. List all dependencies in the Package.swift file for the package you want to resolve in either ID format or GitURL format:

    dependencies: [
    .package(id: "<SCOPE>.<NAME>", from:"<VERSION>"),
    .package(url: "https:[GitURL]", from: "<VERSION>")
    ]

    Where:

    • <SCOPE> - The package owner or namespace, typically derived from the source repository’s scope

    • <NAME> - The package’s name as specified in the Package.swift manifest

    • <VERSION> - The package version, usually matching a tagged release in the source repository

    • [GitURL] - The GitHub URL of the package

    For example:

    dependencies: [
        .package(id: "apple.swift-nio", from: "2.65.0"),
        .package(id: "vapor.fluent", from: "4.8.0"),
        .package(id: "pointfreeco.swift-composable-architecture", from: "1.10.0"),
        .package(url: "https://github.com/baekteun/EventLimiter.git", from: "1.0.0")
        .package(id: "google.swift-protobuf", from: "1.27.0")
    ]
  2. Run the following command to resolve Swift packages:

    swift package resolve --replace-scm-with-registry
  3. Run the following command to perform a Swift build:

    swift build --replace-scm-with-registry

Caution

For successful proxying of all Swift transitive dependencies, it is mandatory to use the following flag with swift build and swift package resolve.

--replace-scm-with-registry

Publish Swift Packages

After configuring registry and authentication, publish Swift packages to a Nexus hosted repository using the Swift PM publish command.

swift package-registry publish <package-id> <version>

Where:

  • <package-id> - Package identifier in scope.package-name format (lowercase); for example com.example.mypackage

  • <version> - Semantic version, for example 1.0.0

Example:

cd /path/to/your-package

# Publish package
swift package-registry publish example.mypackage 1.0.0

Note

Publishing Swift packages is not supported on Windows. Windows users can proxy, resolve and build dependencies, but cannot publish packages.