<div dir="ltr">The need for a feature such as this was pointed out some time ago. A proposal to allow dependencies to be declared with increased granularity has already been written, reviewed, and accepted! Here it is:<div><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md" target="_blank" style="font-size:12.800000190734863px">https://github.com/apple/swift<wbr>-evolution/blob/master/proposa<wbr>ls/0146-package-manager-<wbr>product-definitions.md</a><div><br></div><div>According to the authors, the proposal was meant to be a more general solution that enables specifying test dependencies as well as other use cases:</div><div><a href="https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20161114/000735.html">https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20161114/000735.html</a><br></div><div><br></div><div>The proposal came up for review, received no feedback, and was accepted as-is.</div><div><br></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 27, 2016 at 5:41 PM, thislooksfun via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Does anyone else have any thoughts on this, or should I go ahead an assemble a PR?<br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br>-thislooksfun (tlf)</div>

</div><div><div class="gmail-h5">
<br><div><blockquote type="cite"><div>On Dec 26, 2016, at 1:56 PM, thislooksfun &lt;<a href="mailto:thislooksfun@repbot.org" target="_blank">thislooksfun@repbot.org</a>&gt; wrote:</div><br class="gmail-m_-3513457455857881725Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>(I think this is the right place for this suggestion, but please let me know if I&#39;m mistaken)</div><div><br></div>There is currently no supported way to have some dependencies only used for testing (`swift test`), and the workarounds for it, while workable, are unnecessary crude.<div><br></div><div>Currently, what a lot of projects are doing is defining a `.Package.test.swift` file that is then copied over `Package.swift` when tests are to be run (on external CI, for example). While this works, it adds a extra step and another point of failure (if you forget to add a new dependency to both `Package` files, for example.</div><div><br></div><div>What I propose is a new section of `Package.swift`, labelled either `testDependencies` or `devDependencies`, and the modules referenced within are only loaded/compiled when running `swift test`</div><div><br></div><div><pre style="color:inherit;margin-top:15px;margin-bottom:15px;font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal">// Package.swift
import PackageDescription
let package = Package(
    name: &quot;Project&quot;,
    targets: [
      Target(name: &quot;BoxioDebug&quot;, dependencies: [&quot;Core&quot;]),
    ],
    dependencies: [
<span class="gmail-m_-3513457455857881725Apple-tab-span" style="white-space:pre-wrap">        </span>//Same as before
    ],
    testDependencies: [
        .Package(url: &quot;<a href="https://github.com/FooBar/PackageOnlyNeededForTesting.git" target="_blank">https://github.com/FooBar/<wbr>PackageOnlyNeededForTesting.<wbr>git</a>&quot;, majorVersion: 1),
    ]
)
</pre><div><br class="gmail-m_-3513457455857881725webkit-block-placeholder"></div><div>This solves having to manually switch out Package files or `.Package` statements inside one Package file when trying to run tests, and keeps all dependencies neatly organized in one file.</div><div><br></div><div>This change is purely additive and optional, no existing code needs to change for this to be added.</div><div><br></div><div>A real world example is a dependency on Quick (or another such testing framework), that itself uses XCTest, and thus crashes when being run outside of `swift test` (add Quick to Package.swift, run `swift build` and run the compiled binary). With the new `test[dev]Dependencies`, running `swift build` wouldn&#39;t even see Quick, and thus would compile and run correctly, but `swift test` would both see and use Quick for running the test suite.</div><div><br></div><div><br></div><div><b>Other solutions considered:</b></div><div>Another potential solution is to only compile the dependencies that were actually used when running `swift build`, since that seems to be the cause of the above problem.</div><div><br></div><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br>-thislooksfun (tlf)</div>

</div>

<br></div></div></div></blockquote></div><br></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div></div></div>