Dependency Resolution
Dependency resolution in Gradle can largely be thought of as a two-step process.
First, the graph resolution phase constructs the dependency graph based on declared dependencies. Second, the artifact resolution phase fetches the actual files (artifacts) for the resolved components:
-
Graph resolution phase:
-
Driven by declared dependencies and their metadata
-
Uses the request attributes defined by the configuration being resolved
-
-
Artifact resolution phase:
-
Based on nodes in the resolved dependency graph
-
Matches each node to a variant and an artifact
-
The outcome of these processes can be accessed via different APIs, each designed for specific use cases.
1. Graph Resolution
During the graph resolution phase, Gradle downloads and analyzes component metadata (GMM, POM, or Ivy XML) for declared and transitive dependencies. This information is used to construct a dependency graph, which models the relationships between different components and their variants. You can learn about how the graph is constructed in Understanding the Dependency Resolution Model.
The ResolutionResult
API represents the output of the graph resolution phase, providing access to the resolved dependency graph without triggering artifact downloads.
The graph itself focuses on component variants, not the artifacts (files) associated with those variants:
-
ResolvedComponentResult
- Represents a resolved component in the raw dependency graph. -
ResolvedVariantResult
- Represents a resolved variant of a component in the raw dependency graph.
See Graph Resolution to learn more.
2. Artifact Resolution
Once the dependency graph is resolved, the artifact resolution phase determines which actual files (artifacts) need to be downloaded or retrieved.
An ArtifactView
operates on top of the resolved graph, defined by the ResolutionResult
.
It allows you to query for specific artifacts based on attributes.
The same attributes used during graph resolution typically guide artifact selection.
The ArtifactView
API provides flexible ways to access these resolved artifacts:
-
FileCollection
- A flat list of files, which is the most commonly way to work with resolved artifacts. -
ArtifactCollection
- Offers access to both the metadata and the files of resolved artifacts, allowing for more advanced artifact handling.
See Artifact Resolution to learn more.
Controlling Resolution
An ArtifactTransform
modifies the content of an artifact during dependency resolution, such as converting JAR files into custom formats.
An ArtifactView
permits customizing the artifact selection process, for example filtering components or requesting attributes that trigger artifact transforms.
When used together:
-
Register a
ArtifactTransform
to process artifacts. -
Configure an
ArtifactView
to select artifacts based on attributes that differ from the original graph. -
Query the transformed artifacts via the
ArtifactView
to access or process the transformed files.
See Artifact Views and Artifact Transforms to learn more.
Next Step: Learn about Graph Resolution >>