# How to add local Swift Package as dependency?

**URL:** <https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457>\
**Category:** Using Swift\
**Created:** [June 29, 2019, 4:07pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457 "2019-06-29T16:07:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lolgear](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lolgear/32/4790_2.png) [@lolgear](https://forums.swift.org/u/lolgear)\
**Post date:** [June 29, 2019, 4:07pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/1 "2019-06-29T16:07:04Z")

</div>

Well, Xcode 11 beta 2 suggests only remote URLs, right?  
Can I add local Swift Package as dependency to test it?

---

<div class="post-metadata">

**Author:** ![Aciid](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/aciid/32/429_2.png) [@Aciid](https://forums.swift.org/u/Aciid)\
**Post date:** [June 29, 2019, 4:10pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/2 "2019-06-29T16:10:21Z")

</div>

You can drag the package into a workspace/project to add it as a local package.

---

<div class="post-metadata">

**Author:** ![lolgear](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lolgear/32/4790_2.png) [@lolgear](https://forums.swift.org/u/lolgear)\
**Post date:** [June 29, 2019, 4:12pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/3 "2019-06-29T16:12:51Z")

</div>

No luck.  
It adds only `Package.swift`.  
Compiler error: `No such module 'PackageDescription'`.

---

<div class="post-metadata">

**Author:** ![linqingmo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/linqingmo/32/2442_2.png) [@linqingmo](https://forums.swift.org/u/linqingmo)\
**Post date:** [June 29, 2019, 9:43pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/4 "2019-06-29T21:43:37Z")

</div>

[https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md)

```swift
Clibgit$ git init
Clibgit$ git add .
Clibgit$ git commit -m "Initial Commit"
Clibgit$ git tag 1.0.0

// other package
import PackageDescription

let package = Package(
    name: "example",
    dependencies: [
        .package(url: "../Clibgit", from: "1.0.0")
        //.package(path: "../Clibgit") // is also fine
    ]
)

```

And if you want to add to your app target.  
File -\> Swift Packages -\> Add Package Dependency...  
Enter package repository URL -\> file:///Users/.../Clibgit -\> Next.  
Note: you need to commit to git here. If your package dose not commit to git, Xcode can't find it.

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [June 29, 2019, 11:56pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/5 "2019-06-29T23:56:18Z")

</div>

> [@linqingmo](#):
>
> ```swift
> .package(url: "../Clibgit", from: "1.0.0")
> //.package(path: "../Clibgit") // is also fine
> 
> ```

Those are very different.

The URL one requires it to be pointing at a git repository and treats that repository the same as it would a remote one, cloning it and checking out particular versions or revisions. The source you see in Xcode is managed by SwiftPM and will be “locked” and uneditable.

The path one just directly uses whatever is currently in the file system at that location. I think you can even use it that way without either package having a Git repository at all. You will be able to edit the source you see in Xcode directly.

(Caveat: I’m speaking in terms of Xcode 10.2, but the [related documentation of SwiftPM](https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescription.md#methods-3) looks like it’s still the same.)

---

<div class="post-metadata">

**Author:** ![S2Ler](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/s2ler/32/11355_2.png) [@S2Ler](https://forums.swift.org/u/S2Ler)\
**Post date:** [June 30, 2019, 6:43pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/6 "2019-06-30T18:43:21Z")

</div>

Just drag and drop the folder where Package.swift is located too Xcode and then you can link this package to targets. I used this approach many times already without any issues.

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [October 20, 2019, 11:49am UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/7 "2019-10-20T11:49:28Z")

</div>

> [@Aciid](#):
>
> You can drag the package into a workspace/project to add it as a local package.

> [@S2Ler](#):
>
> Just drag and drop the folder where Package.swift is located too Xcode and then you can link this package to targets. I used this approach many times already without any issues.

I admit some **detailed** how-to would be appreciated. I've been fiddling with Xcode, drag&dropping all that I could reasonably think of, added my local package to the "Link Binary with Libraries" build phase, etc, without any success so far.

My setup:

- xCodeProject.xcodeproj
- xCodeProject
  - AppDelegate.swift
  - ...

- Package
  - Package.swift
  - Sources
    - Product
      - ...

The goal: be able to `import Product` from AppDelegate.swift without "No such module 'Product'" error.

Why? I'm trying to reduce a [bug](https://github.com/groue/GRDB.swift/issues/636) in Xcode 11.2 beta 2, and I'm testing the hypothesis that the bug only happens when some code is imported from a swift package.

Thanks

**Edit** : see solution in the next message.

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [October 20, 2019, 12:06pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/8 "2019-10-20T12:06:18Z")

</div>

I eventually managed to do it.

1. Drag the package folder which contains the Package.swift into your Xcode project

2. Click the Plus button in the "Link Binary with Libraries" section, locate the package in the modal dialog, select the gray library icon inside the package, and add this one.

3. Build your Xcode project and move on to your next interesting task

Trouble is that Xcode lets you drag the brown package icon to the "Link Binary with Libraries" section of the "Build Phases" tab of your Xcode target. Don't do that: _this has no (useful) effect._

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [October 20, 2019, 7:43pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/9 "2019-10-20T19:43:39Z")

</div>

What confused me was that nothing useful happens if you drag the manifest into Xcode. You do double click _the manifest_ in order to _open_ a package in Xcode, but you have to drag _its parent directory_ into Xcode to _add_ a package to a pre‐existing project. I expended about half an hour trying to figure it out when I first got Xcode 11. But in the end everything worked and the problem really was just me.

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [October 20, 2019, 8:47pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/10 "2019-10-20T20:47:43Z")

</div>

When this happens, the problem is _never_ you. That's why we tell those stories.

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [October 20, 2019, 9:02pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/11 "2019-10-20T21:02:39Z")

</div>

Granted. It _was_ unintuitive and confusing and that could use improvement. All I meant was that I was relieved to be able to simply rethink my assumptions, and that I didn’t have to wait months for a bug fix or wrangle some awkward workaround.

---

<div class="post-metadata">

**Author:** ![viktorcode](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/viktorcode/32/7737_2.png) [@viktorcode](https://forums.swift.org/u/viktorcode)\
**Post date:** [October 22, 2019, 10:39am UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/12 "2019-10-22T10:39:44Z")

</div>

The proper way to add a local Swift Package is via menu in Xcode:  
Swift Packages -\> Add Package Dependency...  
And type the full URL pointing to your package folder, starting from file:// prefix (it is a local URL after all).

Take note, only the committed changes in the package propagate to the project builds. I.e. it behaves like a fully remote package, despite the fact that you can still edit its sources from the same Xcode project.

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [October 22, 2019, 11:33am UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/13 "2019-10-22T11:33:29Z")

</div>

> [@viktorcode](#):
>
> And type the full URL pointing to your package folder, starting from file:// prefix (it is a local URL after all).

Didn't think about this one. Thanks!

We'll eventually gather enough information here in order to workaround the UI oddities of Xcode. Maybe some Apple engineer will read this thread and make the necessary changes to Xcode so that we developers don't lose hours of clueless guesses :-)

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [October 22, 2019, 7:50pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/14 "2019-10-22T19:50:02Z")

</div>

> [@viktorcode](#):
>
> The proper way to add a local Swift Package is via menu in Xcode:  
> Swift Packages -\> Add Package Dependency...  
> And type the full URL pointing to your package folder, starting from file:// prefix (it is a local URL after all).

I repeat from [my earlier comment](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/5) that using a URL and using a path have vastly different semantics. In addition, relative URLs do not work, so you run into trouble if you are part of a team or use CI: clone the project to another device and nothing will work. There _is_ a time and place for local URLs, but they are not a replacement for relative paths.

If we are looking for what is “proper”, the very first answer upthread came from [a rather authoritative source](https://github.com/apple/swift-package-manager/graphs/contributors):

> [@Aciid](#):
>
> You can drag the package into a workspace/project to add it as a local package.

---

<div class="post-metadata">

**Author:** ![viktorcode](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/viktorcode/32/7737_2.png) [@viktorcode](https://forums.swift.org/u/viktorcode)\
**Post date:** [October 22, 2019, 8:01pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/15 "2019-10-22T20:01:43Z")

</div>

Well, I came forward with that answer because it seemed to me some people had issues with dragging and dropping packages. And since the package integration system in Xcode is built around URLs I called the way when you in add a local package by typing in its URL "proper". I apologise if there is any confusion 😊

---

<div class="post-metadata">

**Author:** ![MikeIsaev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mikeisaev/32/3446_2.png) [@MikeIsaev](https://forums.swift.org/u/MikeIsaev)\
**Post date:** [October 31, 2019, 4:51am UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/16 "2019-10-31T04:51:53Z")

</div>

`Drag&Drop` is not the same. It should be possible to add packages through SPM with relative paths as it works with `Package.swift`, but for Xcode's `File -> Swift Packages -> Add Package Dependency...` menu.

---

<div class="post-metadata">

**Author:** ![joesus](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joesus/32/24541_2.png) [@joesus](https://forums.swift.org/u/joesus)\
**Post date:** [November 1, 2019, 4:10pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/17 "2019-11-01T16:10:43Z")

</div>

Your answer was super helpful and got me unblocked for local development. I still need to be able to write a CI test to make sure that the proper symbols are exposed etc... it's simply not enough to have a test that the package target itself will build. Are you aware of any ongoing work on adding proper pathing to Xcode so that we can have proper integration tests? Have you personally found a workaround for this?

---

<div class="post-metadata">

**Author:** ![viktorcode](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/viktorcode/32/7737_2.png) [@viktorcode](https://forums.swift.org/u/viktorcode)\
**Post date:** [November 1, 2019, 4:31pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/18 "2019-11-01T16:31:37Z")

</div>

Sorry, I don't think I understand your question. How to test that the package correctly exposes its symbols , like everything that has to be marked public is marked as such? Well, unit tests being compiled in separate module cannot access anything which is not exposed through public or not marked as @testable. Is that what you asking?

---

<div class="post-metadata">

**Author:** ![joesus](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joesus/32/24541_2.png) [@joesus](https://forums.swift.org/u/joesus)\
**Post date:** [November 1, 2019, 4:41pm UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/19 "2019-11-01T16:41:53Z")

</div>

I guess I mean as an integration test. Outside the context of a swift package. After I’ve created the package I want to run a smoke test with a separate project to make sure it can be consumed by that project as expected. This just means importing the libraries, making sure they compile in the context of an external app, and referencing some symbols as a sanity check.

The project I’m working with is sort of complex so it’s not a given that a consuming project will build the same way as the package on its own. I need to know that both are correct. 🙂

---

<div class="post-metadata">

**Author:** ![viktorcode](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/viktorcode/32/7737_2.png) [@viktorcode](https://forums.swift.org/u/viktorcode)\
**Post date:** [November 4, 2019, 9:04am UTC](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/20 "2019-11-04T09:04:58Z")

</div>

Hmm I don't think I have ever though about implementing buildability test as something separate. technically one could create a separate test project which would be using all API types and calls that should be exposed by the package in question. And if this project builds the test passes. However, using CI implies that your package should already be deployed somewhere to be accessible via its URL by the build machine. So, it won't be local.

[Next page](https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457.md?page=2)
