19

I started using new Xcode 11 which integrates SPM.

I added first dependency to my project:

enter image description here

but detected that files are not fetched into my project folder but into Xcode's cache:

enter image description here

I would like to commit all my dependencies files into my main project repository so my question is:

Is it possible to change location of fetched packages via SPM using Xcode 11?

Kamil Harasimowicz
  • 4,684
  • 5
  • 32
  • 58
  • 1
    Why do you want to commit dependencies? You can commit the .resolved file and everyone in your team will have the same SPM version – Parag Bafna Sep 09 '19 at 11:17
  • 6
    Same reasons like here: https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control Especially 2nd dot about availability of dependencies. – Kamil Harasimowicz Sep 09 '19 at 11:34
  • I don't think it's possible to change the path. You can keep separate copy of the repo. – Parag Bafna Sep 12 '19 at 11:10
  • If you want to do this, why are you using the package manager at all? Just clone all of the projects and copy them into your repository. – Rudedog Sep 25 '19 at 19:43
  • 8
    @Rudedog There is a simple reason - SPM is easer to use and it gives you automatic updates. However, for security reasons deployment builds can run on servers that do not have direct access to github and similar public repos. – Sulthan Feb 15 '21 at 13:08

2 Answers2

4

It's somewhat possible, although the solution isn't necessarily a good or great practice, so I can't recommend.

  1. Set the DerivedData in workspace settings to be relative to the workspace.
  2. Add gitignore rules such that the workspace/WORKSPACE_NAME_DIR/SourcePackages/checkouts and related files are includes. Maybe best to ensure repositories directory is not included.
  3. Add a Run Script phase to remove .git and .gitignore files in the checkouts directory.

Obviously, this is fragile largely through fighting the way SPM works. The workspace settings are per person so it's not great in teams.

Scott McKenzie
  • 16,052
  • 8
  • 45
  • 70
3

SwiftPM integration has been setup to prevent this. It clones the files into a DerivedData/ProjectName-[RandomStuff]. You should commit your Package.resolved into the repo to ensure that you get the same version of each dependency across clones of the project.

bscothern
  • 1,894
  • 11
  • 15