You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You define constraints for dependencies when you add them to your package, and those constraints can not always be met.
8
+
9
+
<!-- link to CLI docs for swift package resolve -->
10
+
Prior to running a build or test, or when you run `swift package resolve`, the package manager walks through the dependencies in your package, and all their dependencies recusively, to build a complete list.
11
+
It then attempts to choose a version of each dependency that fits within the constraints of your package, and any constraints provided by your dependencies.
12
+
13
+
If all the dependencies are available and resolved, the versions are recorded locally in the file `Package.resolved`.
14
+
You can view these dependencies using the command `swift package show-dependencies`, which provides a succint list of the entire set of dependencies.
15
+
<!-- link to CLI docs for swift package show-dependencies -->
16
+
17
+
<!-- this should q include some meaningful advice on how to identify and resolve the failure conditions -->
18
+
19
+
### Failure Scenarios
20
+
21
+
There are a variety of scenarios that may occur, including:
22
+
23
+
- term Inappropriate Versioning: A package may specify an inappropriate version for a release.
24
+
For example, a version is tagged `1.2.3`, but introduces extensive, breaking API changes that should be reflected by a major version bump to `2.0.0`.
25
+
26
+
- term Incompatible Major Version Requirements: A package may have dependencies with incompatible version requirements for the same package.
27
+
For example, if `Foo` depends on `Baz` at version `~>1.0` and `Bar` depends on `Baz` at version `~>2.0`, then there is no one version of `Baz` that can satisfy both requirements.
28
+
This situation often arises when a dependency shared by many packages updates to a new major version, and it takes a long time for all of those packages to update their dependency.
29
+
30
+
- term Incompatible Minor or Update Version Requirements: A package may have dependencies that are specified too strictly, such that version requirements are incompatible for different minor or update versions.
31
+
For example, if `Foo` depends on `Baz` at version `==2.0.1` and `Bar` depends on `Baz` at version `==2.0.2`, once again, there is no one version of `Baz` that can satisfy both requirements.
32
+
This is often the result of a regression introduced in a patch release of a dependency, which causes a package to lock that dependency to a particular version.
33
+
34
+
- term Namespace Collision: A package may have two or more dependencies that have the same name.
35
+
For example, a `Person` package depends on an `Addressable` package that defines a protocol for assigning a mailing address to a person, as well as an `Addressable` package that defines a protocol for speaking formally to another person.
36
+
37
+
- term Broken Software: A package may have a dependency with an outstanding bug that is impacting usability, security, or performance.
38
+
This may simply be a matter of timeliness on the part of the package maintainers, or a disagreement about their expectations for the package.
39
+
40
+
- term Global State Conflict: A package may have two or more dependencies that presume to have exclusive access to the same global state.
41
+
For example, one package may not be able to accommodate another package writing to a particular file path while reading from that same file path.
42
+
43
+
- term Package Becomes Unavailable: A package may have a dependency on a package that becomes unavailable.
44
+
This may be caused by the source URL becoming inaccessible, or maintainers deleting a published version.
Copy file name to clipboardExpand all lines: Sources/PackageManagerDocs/Documentation.docc/IntroducingPackages.md
+8-40Lines changed: 8 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,17 @@ Learn to create and use a Swift package.
7
7
A package consists of Swift source files, including the `Package.swift` manifest file.
8
8
The manifest file, or package manifest, defines the package's name and its contents using the PackageDescription module.
9
9
10
-
Each package declares `products`, a list of what the package produces.
10
+
Each package declares `Products`, a list of what the package produces.
11
11
Types of products include libraries, executables, and plugins:
12
12
13
13
- A library defines a module that can be imported by other Swift code.
14
14
- An executable is a program that can be run by the operating system.
15
15
- A plugin is executable code that the Swift Package Manager may use to provide additional commands or build capabilities.
16
16
17
-
Each of the products is made up of one or more targets, the basic building block of a Swift package.
17
+
The package can also declare `Dependencies`, most frequently other swift packages that provide modules you use.
18
+
Dependencies can also provide macros, plugins, or reference system or binary (non-source) dependencies.
19
+
20
+
Each product is made up of one or more `Targets`, the basic building block of a Swift package.
18
21
Each target specifies an output, may declare one or more dependencies on other targets within the same package and on products vended by the package’s dependencies.
19
22
A target may define a library, a test suite, an executable, an macro, a binary dependency, and so on.
20
23
@@ -31,7 +34,7 @@ For example, a module that provides functionality for making network requests co
31
34
And if a new module comes along that does a better job, it can be swapped in easily, with minimal change.
32
35
By embracing modularity, you can focus on the interesting aspects of the problem at hand, rather than getting bogged down solving problems you encounter along the way.
33
36
34
-
As a rule of thumb: more modules is probably better than fewer modules.
37
+
As a rule of thumb: more modules are probably better than fewer modules.
35
38
The package manager is designed to make creating both packages and apps with multiple modules as easy as possible.
36
39
37
40
### About Dependencies
@@ -43,41 +46,6 @@ In addition to downloading and building the source code for a dependency, that d
43
46
To complicate matters further, a dependency may specify version requirements, which may have to be reconciled with the version requirements of other modules with the same dependency.
44
47
45
48
The role of the package manager is to automate the process of downloading and building all of the dependencies for a project, and minimize the coordination costs associated with code reuse.
46
-
47
-
### Dependency Hell
48
-
49
-
“Dependency Hell” is the colloquialism for a situation where the graph of dependencies required by a project cannot be met.
50
-
The user is then required to solve the scenario, which is usually a difficult task:
51
-
52
-
1. The conflict may be in unfamiliar dependencies (of dependencies) that the user did not explicitly request.
53
-
2. Due to the nature of development it would be rare for two dependency graphs to be the same.
54
-
Thus the amount of help other users (often even the package authors) can offer is limited.
55
-
Internet searches will likely prove fruitless.
56
-
57
-
A good package manager should be designed from the start to minimize the risk of dependency hell, and where this is not possible, to mitigate it and provide tooling so that the user can solve the scenario with a minimum of trouble.
49
+
A good package manager should be designed from the start to minimize the risk of failing to resolve dependencies, and where this is not possible, to mitigate it and provide tooling so that the user can solve the scenario with a minimum of trouble.
58
50
The <doc:PackageManagerCommunityProposal> contains our thoughts on how we intend to iterate with these hells in mind.
59
-
60
-
The following are some of the most common “dependency hell” scenarios:
61
-
62
-
* Inappropriate Versioning - A package may specify an inappropriate version for a release.
63
-
For example, a version is tagged `1.2.3`, but introduces extensive, breaking API changes that should be reflected by a major version bump to `2.0.0`.
64
-
65
-
* Incompatible Major Version Requirements - A package may have dependencies with incompatible version requirements for the same package.
66
-
For example, if `Foo` depends on `Baz` at version `~>1.0` and `Bar` depends on `Baz` at version `~>2.0`, then there is no one version of `Baz` that can satisfy both requirements.
67
-
This situation often arises when a dependency shared by many packages updates to a new major version, and it takes a long time for all of those packages to update their dependency.
68
-
69
-
* Incompatible Minor or Update Version Requirements - A package may have dependencies that are specified too strictly, such that version requirements are incompatible for different minor or update versions.
70
-
For example, if `Foo` depends on `Baz` at version `==2.0.1` and `Bar` depends on `Baz` at version `==2.0.2`, once again, there is no one version of `Baz` that can satisfy both requirements.
71
-
This is often the result of a regression introduced in a patch release of a dependency, which causes a package to lock that dependency to a particular version.
72
-
73
-
* Namespace Collision - A package may have two or more dependencies that have the same name.
74
-
For example, a `Person` package depends on an `Addressable` package that defines a protocol for assigning a mailing address to a person, as well as an `Addressable` package that defines a protocol for speaking formally to another person.
75
-
76
-
* Broken Software - A package may have a dependency with an outstanding bug that is impacting usability, security, or performance.
77
-
This may simply be a matter of timeliness on the part of the package maintainers, or a disagreement about their expectations for the package.
78
-
79
-
* Global State Conflict - A package may have two or more dependencies that presume to have exclusive access to the same global state.
80
-
For example, one package may not be able to accommodate another package writing to a particular file path while reading from that same file path.
81
-
82
-
* Package Becomes Unavailable - A package may have a dependency on a package that becomes unavailable.
83
-
This may be caused by the source URL becoming inaccessible, or maintainers deleting a published version.
51
+
Read <doc:ExploreDependencies> for more information on how the package manager resolves and records dependencies.
0 commit comments