diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 34465eb29e6..29f5f04de3d 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -790,7 +790,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan { if product.targets.contains(target) { staticTargets.append(target) } else if product.type == .test && (target.underlyingTarget as? SwiftTarget)?.supportsTestableExecutablesFeature == true { - if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5 { + // Only "top-level" targets should really be considered here, not transitive ones. + let isTopLevel = topLevelDependencies.contains(target.underlyingTarget) || product.targets.contains(target) + if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5, isTopLevel { staticTargets.append(target) } }