Package dependency in own package

There's two places that you need to add dependencies to a swift package, and the second snippet isn't typically included in project READMEs - depending on the package, it can be a little quirky or hard to work out what to use.

The first piece is what you copied - that adds a dependency stanza to the overall Package declaration. The second is what I suspect you were missing - adding a reference to the target that needs the dependency.

The second place, that wasn't obviously referenced in the README of the library project, is the bit you add to a specific target:

dependencies: [
    .product(name: "SQLite", package: "SQLite.swift")
]

And to show you a fuller example, the Package.swift below is a quick-n-dirty example using the specific dependency you referenced:

// swift-tools-version: 5.8

import PackageDescription

let package = Package(
    name: "temp",
    products: [
        .library(
            name: "temp",
            targets: ["temp"]),
    ],
    dependencies: [
        .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1")
    ],
    targets: [
        .target(
            name: "temp",
            dependencies: [
                .product(name: "SQLite", package: "SQLite.swift")
            ]
        ),
        .testTarget(
            name: "tempTests",
            dependencies: ["temp"]),
    ]
)

5 Likes