Swift Package Invalid Manifest Error on Nightly Jammy Client — Works on latest version

Hi Swift community,

I'm currently encountering an issue with the nightly-jammy version of the Swift client while running an end-to-end integration test for Swift packages hosted on JFrog Artifactory. The same setup works perfectly fine with the latest stable Swift client, so I suspect this might be a regression or behavioral change introduced in the nightly jammy.

/swifttest/Package.swift:14:13: error: expected ',' separator
dependencies: [ .package(url: "https://secureartifactory.com:443/artifactory/swift-local-yi4ao7qpes/test/swiftDep", from: "1.0.0"), ],
                                     ^

/swifttest/Package.swift:14:13: error: expected expression in container literal
/swifttest/Package.swift:14:1: error: cannot find 'dependencies' in scope

This only fails on nightly-jammy, but passes successfully on the latest released client. The manifest structure hasn't been changed for quite some time.

My Inference

It seems like the nightly build is interpreting the manifest file differently, potentially due to changes in manifest parsing.

Request

Could someone from the community or SwiftPM team help confirm if this is a known change with nightly jammy? Any pointers or release notes that might help us adapt to this change (if intended) would be appreciated.

Package.swift file for reference

// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
                                             
import PackageDescription
                                             
let package = Package(
    name: "swiftpkg",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "swiftpkg",
            targets: ["swiftpkg"]
        ),
dependencies: [ .package(url: "https://github.com/jfrog-qa/SwiftDepTest", from: "1.0.0"), ],
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
       // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "swiftpkg"
        ),
        .testTarget(
            name: "swiftpkgTests",
            dependencies: ["swiftpkg"]
        ),
    ]
 )

Thanks in advance!

— Shashank

Would you be able to file a bug report with detailed reproduction steps and exact version of your toolchain and environment on SwiftPM's GitHub issues page?

Thanks!i

Sure will do. Thanks for pointing out to right place.

:eyes: I posted my question there:

Hey @YOCKOW , I am afraid I didnt understand your question. Can you please elaborate?

Hi again :waving_hand:,

Thanks for the pointers earlier. Based on the suggestion from @plemarquand in the GitHub thread, we're now considering replacing our current approach — which uses sed to inject .package lines into Package.swift — with the more resilient swift package add-dependency command.

This change seems necessary since the line numbers in the manifest generated via swift package init have recently shifted (as part of nightly builds), causing our existing E2E tests to fail.

That said, we often add dependencies with version ranges like:

.package(url: "https://example.com/swiftDep.git", "1.0.0"..<"2.0.0")

Does the add-dependency CLI support this form of version specification? I couldn’t find direct references to it in the docs or help command output.

Would appreciate any guidance!

Thanks :raising_hands:

I would suggest also filing this on the GitHub issues page on the SwiftPM repository. Even if it were already implemented (I'm not sure that's the case off the top of my head), not providing documentation or references in command help output would be a bug, your help in filing that is appreciated.

1 Like

I just meant that the content of Package.swift must be a valid Swift code.
Apparently, the array literal in your Package.swift is syntactically invalid.

[
  // Products define the executables and libraries a package produces, making them visible to other packages.
  .library(
    name: "swiftpkg",
    targets: ["swiftpkg"]
  ),
  dependencies: [ .package(url: "https://github.com/jfrog-qa/SwiftDepTest", from: "1.0.0"), ],
]

Executing

swift package add-dependency https://example.com/swiftDep.git --from 1.0.0 --to 2.0.0

will add

.package(url: "https://example.com/swiftDep.git", from: "1.0.0"),

in your Package.swift.
Missing ..< "2.0.0"?
It's OK because from: ... means "up to the next major version".

If you try

swift package add-dependency https://example.com/swiftDep.git --from 1.0.0 --to 2.1.0

then,

.package(url: "https://example.com/swiftDep.git", "1.0.0" ..< "2.1.0"),

will be added.


By the way, in Swift 6.1, swift package add-dependency --help will view the following message:

OVERVIEW: Add a package dependency to the manifest

USAGE: swift package add-dependency <dependency> [--exact <exact>] [--revision <revision>] [--branch <branch>] [--from <from>] [--up-to-next-minor-from <up-to-next-minor-from>] [--to <to>] [--type <type>]

ARGUMENTS:
  <dependency>            The URL or directory of the package to add

OPTIONS:
  --exact <exact>         The exact package version to depend on
  --revision <revision>   The specific package revision to depend on
  --branch <branch>       The branch of the package to depend on
  --from <from>           The package version to depend on (up to the next major version)
  --up-to-next-minor-from <up-to-next-minor-from>
                          The package version to depend on (up to the next minor version)
  --to <to>               Specify upper bound on the package version range (exclusive)
  --type <type>           Specify dependency type (values: url, path, registry; default: url)
  --version               Show the version.
  -h, -help, --help       Show help information.

2 Likes

Hey @YOCKOW ,
Yes, you are right, I was using sedline command to add dependency at a particular line, and since the content of Package.swift changed, this lead to invalid manifest.

Also, thank you for pointing out the --from and --to flags, will use them.

Thanks!