A dependency is a group of Pkl modules and file resources that can be imported within the
project.
Within the project, a dependency can be referenced via dependency notation, where the name
is prefixed with the @
character.
For example, given the following descriptor:
dependencies {
["birds"] {
uri = "package://example.com/birds@1.0.0"
}
}
This enables the following snippet:
import "@birds/canary.pkl" // Import a module from the `birds` dependency
birdIndex = read("@birds/index.txt") // Read a file from the `birds` dependency
A dependency's coordinates can either be specified in the form of a RemoteDependency
descriptor, which gets fetched over the network, or an import of another PklProject file, which
represents a package that exists locally.
Remote dependencies are fetched over HTTPS.
When fetching a remote dependency, two HTTPS requests are made.
Given dependency URI package://example.com/foo@0.5.0
, the following requests are made:
GET https://example.com/foo@0.5.0
to retrieve the metadata JSON file.
- Given the metadata JSON file, make a GET request to the package URI ZIP archive.
If this project is published as a package, these dependencies are included within the published
package metadata.
Local project dependencies
A local project can alternatively be used as a dependency.
This is useful when structuring a single repository that publishes multiple packages.
To specify a local project dependency, import the relative PklProject
file.
The local project dependency must define its own package
.
Example:
dependencies {
["penguins"] = import("../penguins/PklProject")
}
Resolving dependencies
Dependencies must be resolved before they can be used.
To resolve dependencies, run the CLI command pkl project resolve
.
This will generate a PklProject.deps.json
file next to the PklProject
file.
Minimum version selection
Pkl uses the
minimum version selection algorithm 1
to resolve dependencies.
A dependency is identified by its package URI, as well as its major semver number.
To determine the resolved dependencies of a project, the following algorithm is applied:
- Gather all dependencies, both direct and transitive.
- For each package's major version, determine the highest declared minor version.
- Write each resolved dependency to sibling file
PklProject.deps.json
.
A manifest that defines the presence of a project.