Search code examples
swift4swift-package-managerkitura

/src: error: could not find source files for target(s): MyKituraAppTests; use the 'path' property in the Swift 4 manifest to set a custom target path


I'm trying to compile using swift build

Package.swift

// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

// swift-tools-version:x.x
import PackageDescription

let package = Package(
    name: "MyKituraApp",
    dependencies: [
        .package(url: "https://github.com/IBM-Swift/Kitura", from: "2.7.0")
    ],
    targets: [
        .target(
            name: "MyKituraApp",
            dependencies: ["Kitura"],
            path: "Sources"),
        .testTarget(
            name: "MyKituraAppTests",
            dependencies: ["MyKituraApp"],
            path: "Test")
    ]
)

But, I get the following error although I did add the path property.

'MyKituraApp' /src: error: could not find source files for target(s): MyKituraAppTests; use the 'path' property in the Swift 4 manifest to set a custom target path


Solution

  • Without knowing your project structure I can't give you a definite answer but I'll do my best!

    I'm going to assume you've generated your project using the Swift Package Manager tool, something like this: swift package init --type executable

    So... Typically you shouldn't need to set the path property unless you've moved the tests for your application to another directory. The Swift Package Manager, by default, will create a Tests directory and when you do not provide a value for the path property the Swift Package Manager will look for that Tests directory by default when you run swift build. In your path property you are providing a value of Test not Tests

    So my first solution to test would be: To remove the path property from the .testTarget section

    OR

    Rename the path properties value to Tests rather than Test.

    I've provided an example Package.swift that I was able to run swift build with:

    // swift-tools-version:4.2
    // The swift-tools-version declares the minimum version of Swift required to build this package.
    
    import PackageDescription
    
    let package = Package(
        name: "MyKituraApp",
        dependencies: [
            .package(url: "https://github.com/IBM-Swift/Kitura", from: "2.7.0")
        ],
        targets: [
            .target(
                name: "MyKituraApp",
                dependencies: ["Kitura"],
                path: "Sources"),
            .testTarget(
                name: "MyKituraAppTests",
                dependencies: ["MyKituraApp"])
        ]
    )
    

    As you can see I've also removed an extra line from the top of the file: // swift-tools-version:x.x

    You've already provided a swift-tools-version at the top of your file, this line may end up confusing things later down the line.

    I hope this helps!