'Two almost identical targets in Vapor Xcode project

I want to configure Package.swift so that one target would be an extension to another, both of them should share the same code from the one folder, but for the "extended" version there is an additional subfolder. But configuration I try with path fails with "overlapping sources" error. So, how can I make two target with the same source folder?

.target(name: "App", dependencies: [ "Vapor" ... ], exclude: [ "Subfolder" ])
.target(name: "Extended", dependencies: [ "Vapor", ... ], path: "./Sources/App")

swift build ... error: target 'Extended' has sources overlapping sources...


Solution 1:[1]

SwiftPM is strict about one target gets to own the files. So you will need to set up a proper dependency chain for your files.

It sounds like Extended adds more functionality to App in this case. If so you want to have App all the things it currently is. Then have Extended depend on App and build all of the things exclusive to it.

This allows 1 target to own the source files and allows Extended to use the one implementation of those files.

Solution 2:[2]

In my case I had one of my executableTargets path set to the root "."

        .executableTarget(
            name: "ServiceA",
            dependencies: [Vapor..],
            path: "."),
        .executableTarget(
            name: "ServiceB",
            dependencies: [Vapor..]),

After I removed the path from the constructor in ServiceA. I was able to set the proper folders and Xcode was able to infer the path of my executable targets

Sources
|_ServiceA
|_ServiceB
        .executableTarget(
            name: "ServiceA",
            dependencies: [Vapor..])
        .executableTarget(
            name: "ServiceB",
            dependencies: [Vapor..]),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bscothern
Solution 2 Idelfonso Gutierrez