How to avoid that Xcode will resolve git submodule when fetching a Swift package?

Hi, I was under the impression that SPM does not resolve git submodules. That is absolutely fine with me.

Recently I added a git submodule to a Swift package to offload image resources that are only needed for snapshot-based testing during package development. There is no need that SPM has to resolve the git submodule.

However, I encountered that git submodule do get resolved when adding the package to an app target via Xcode 11.5.1

Is this expected? Can this be suppressed?

My main concern is that I want to keep the clone size and time for my Swift package as small as possible.


I was wrong about that. I was later corrected here.

You can probably take advantage of SE‐0226 to accomplish that.

1 Like

Thanks for the clarification and the reference

Thanks for the tip about Package Manager Target Based Dependency Resolution but I am trying to wrap my head around if this easily solves my requirement.

  • My dependency is directories full of images and does not contain any source code.
  • Handling resources will be available in Swift 5.3 (not yet publicly available).
  • Also will images (.png) be automatically detected as resources or do images need to be explicitly declared in Package.manifest one by one?

The spun‐out package would need some basic Swift code too in order to vend the resources through an API.

Official resources support will be better when it becomes available. However, until then...

Since you mention it is development‐time only, I assume the repository is still around when the tests are executed. As long as that is true, you can use URL(fileURLWithPath: #file) to get the path of a particular source file and then delete and append path components to point at an image or other resource beside it. As long as the repository is still present at that path during execution, and your test executable has permission, you should be able to load the image from that path. And it will work no matter where SwiftPM or Xcode decided to put the dependency while building for that particular test run.

1 Like