# Package Manager exported dependencies

**URL:** <https://forums.swift.org/t/package-manager-exported-dependencies/11615>\
**Category:** Package Manager\
**Tags:** dependency-managemen\
**Created:** [April 3, 2018, 5:28am UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615 "2018-04-03T05:28:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maksym\_Grebenets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maksym_grebenets/32/3010_2.png) [@Maksym\_Grebenets](https://forums.swift.org/u/Maksym_Grebenets)\
**Post date:** [April 3, 2018, 5:28am UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/1 "2018-04-03T05:28:47Z")

</div>

Hi, is there a way to have exported dependencies with SPM?

To provide some context, let's say I have a simple `MyLibrary`, which depends on `Result`.  
What I want to achieve is everywhere the `MyLibrary` is used, the `Result` package is available as well.  
Hence the name "exported", because `Result` package is exported as part of `MyLibrary`.

This is possible with CocoaPods.  
This is also possible with Buck, they even have a special `exported_dependencies` option for that.

However, with SPM all dependencies that I list under `dependencies:` seem to be internal and describe what is required to build this package.

Is it possible to achieve with current version of SPM or is it on the roadmap?

---

<div class="post-metadata">

**Author:** ![calebkleveter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/calebkleveter/32/9273_2.png) [@calebkleveter](https://forums.swift.org/u/calebkleveter)\
**Post date:** [April 3, 2018, 11:01am UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/2 "2018-04-03T11:01:42Z")

</div>

Yes, there is a way.

In `MyLibrary`, when you import `Result`, add the `@_exported` annotation to the `import` statement. This will export the module from the target.

```swift
@_exported import Result

```

---

<div class="post-metadata">

**Author:** ![Lope](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lope/32/1453_2.png) [@Lope](https://forums.swift.org/u/Lope)\
**Post date:** [April 3, 2018, 12:33pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/3 "2018-04-03T12:33:31Z")

</div>

> [@calebkleveter](#):
>
> @\_exported

This feels like something internal that should not be used outside of the stdlib and the like (because of leading underscore). Is this safe to use going forward?

---

<div class="post-metadata">

**Author:** ![calebkleveter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/calebkleveter/32/9273_2.png) [@calebkleveter](https://forums.swift.org/u/calebkleveter)\
**Post date:** [April 3, 2018, 1:36pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/4 "2018-04-03T13:36:31Z")

</div>

Everything I read around the web says "don't use it, it could break any time because it's private, etc.". I agree that it could break any time, but that annotation is widely used in some Swift communities and I think a hue and cry would be raised should it be removed.

I found [this thread](https://forums.swift.org/t/exported-and-fixing-import-visibility/9415) that discusses this subject of the visibility of an import and is also the only place I have seen a Core Swift Team member discuss it. From what I read, I don't think there is too much of a concern at this point of its removal, though I could be wrong on that.

---

<div class="post-metadata">

**Author:** ![sharplet](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sharplet/32/6184_2.png) [@sharplet](https://forums.swift.org/u/sharplet)\
**Post date:** [April 3, 2018, 2:17pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/5 "2018-04-03T14:17:04Z")

</div>

I agree that there's a need for a public version of this.

One thing to be aware of about `@_exported import`: it doesn't export operator declarations, so if you export a library that defines operators, consumers will still need to explicitly import the library where those operators are declared.

---

<div class="post-metadata">

**Author:** ![calebkleveter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/calebkleveter/32/9273_2.png) [@calebkleveter](https://forums.swift.org/u/calebkleveter)\
**Post date:** [April 3, 2018, 2:27pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/6 "2018-04-03T14:27:06Z")

</div>

> One thing to be aware of about @\_exported import: it doesn’t export operator declarations, so if you export a library that defines operators, consumers will still need to explicitly import the library where those operators are declared.

You could also just add the declarations to your project, because the implementations are exported.

---

<div class="post-metadata">

**Author:** ![sharplet](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sharplet/32/6184_2.png) [@sharplet](https://forums.swift.org/u/sharplet)\
**Post date:** [April 3, 2018, 3:35pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/7 "2018-04-03T15:35:57Z")

</div>

> You could also just add the declarations to your project, because the implementations are exported.

True, but that's taking on an extra maintenance burden — what if your operator declarations get out of sync with your dependency's? I suppose as long is a consumer isn't importing both it's probably fine, but it could get tricky.

---

<div class="post-metadata">

**Author:** ![davedelong](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davedelong/32/38708_2.png) [@davedelong](https://forums.swift.org/u/davedelong)\
**Post date:** [April 3, 2018, 3:56pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/8 "2018-04-03T15:56:09Z")

</div>

> [@sharplet](#):
>
> One thing to be aware of about @\_exported import: it doesn’t export operator declarations, so if you export a library that defines operators, consumers will still need to explicitly import the library where those operators are declared.

I don't believe this is correct. When I use `@_exported import Foo` inside of module `Bar`, then operators from `Foo` show up just fine in `Bar` without having to explicitly `import Foo` in each respective file. I mention this in my blog post here: [Simplifying Swift framework development | Dave DeLong](https://davedelong.com/blog/2018/01/19/simplifying-swift-framework-development/)

---

<div class="post-metadata">

**Author:** ![sharplet](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sharplet/32/6184_2.png) [@sharplet](https://forums.swift.org/u/sharplet)\
**Post date:** [April 3, 2018, 5:38pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/9 "2018-04-03T17:38:44Z")

</div>

> [@davedelong](#):
>
> When I use @\_exported import Foo inside of module Bar, then operators from Foo show up just fine in Bar without having to explicitly import Foo in each respective file.

This is correct within `Bar`, but for an app `Foobar` which imports `Bar` and _not_ `Foo`, they will get the `Operator is not a known binary operator` error unless they also import `Foo` to get the operator declaration(s).

---

<div class="post-metadata">

**Author:** ![Maksym\_Grebenets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maksym_grebenets/32/3010_2.png) [@Maksym\_Grebenets](https://forums.swift.org/u/Maksym_Grebenets)\
**Post date:** [April 4, 2018, 12:24am UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/10 "2018-04-04T00:24:43Z")

</div>

Thanks all for the answers!

`@_exported` did the trick.  
I realize that `_` means it's private, but it works for us so far, since package manager is (yet) not the main dependency management tool, so we won't be impacted if `@_exported` is removed. Well, maybe we'll be a bit upset 🙂

---

<div class="post-metadata">

**Author:** ![CypherPoet](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cypherpoet/32/20897_2.png) [@CypherPoet](https://forums.swift.org/u/CypherPoet)\
**Post date:** [December 14, 2021, 6:06pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/11 "2021-12-14T18:06:15Z")

</div>

This is a super-useful feature that's existed for a while now and seems to be widely used throughout the community (by myself included 🙂).

I'd be very curious to know if there's any movement towards making it an "official" part of the language -- or, if not, if there's any planned alternative.

---

<div class="post-metadata">

**Author:** ![rauhul](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rauhul/32/35207_2.png) [@rauhul](https://forums.swift.org/u/rauhul)\
**Post date:** [December 14, 2021, 7:15pm UTC](https://forums.swift.org/t/package-manager-exported-dependencies/11615/12 "2021-12-14T19:15:05Z")

</div>

> [@CypherPoet](#):
>
> I'd be very curious to know if there's any movement towards making it an "official" part of the language -- or, if not, if there's any planned alternative.

Check out Becca's proposal here: [[Pre-Pitch] Import access control: a modest proposal](https://forums.swift.org/t/pre-pitch-import-access-control-a-modest-proposal/50087)

(Best to move the conversation over to that thread)
