I'm having an issue resolving some dependencies in the test suite for my app when using a Swift Package in my test target.
Here's the setup: We have a Swift Package that contains two products. One product is the main library that is used throughout our app. The other product is a library of testing utilities, like mocks and such. This is a simplified version of its Package.Swift file with actual package/target/library/dependency names changed.
let package = Package(
name: "Library",
platforms: [
.iOS(.v14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Library",
targets: ["Library"]),
.library(
name: "LibraryTestUtilities",
targets: ["LibraryTestUtilities"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: <DependencyA URL>, .upToNextMajor(from: "1.0.0")),
.package(url: <DependencyB URL>,.upToNextMajor(from: "1.0.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Library",
dependencies: [
.product(name: "DependencyA", package: "DependencyA"),
.product(name: "DependencyB", package: "DependencyB")
])
,
.target(
name: "LibraryTestUtilities",
dependencies: [
.target(name: "Library")
]
),
.testTarget(
name: "LibraryTests",
dependencies: ["Library", "LibraryTestUtilities"]),
]
)
In our App, our target is linked to the "Library" product. Our test target is linked to "LibraryTestUtilities". When we try to build the test target, we're getting build errors in the form No Such Module DependencyA
when compiling the "Library" product. Swift Package Manager is not able to link the dependencies from "Library" even though "LibraryTestUtiltities" is dependent on "Library". There are also no such issues resolving the "Library" dependencies when building the main app target or when building/testing the "Library" package directly. We are only having issues when trying to link the "LibraryTestUtilities" target to our app's test target through Build Phases -> Link Binary With Libraries.
I couldn't find any similar issues encountered online so perhaps our setup is misguided, though there doesn't seem to be any obvious reason why it wouldn't work. We would appreciate any help, thanks!