Skip to navigation

Gradle Constraints vs Dependencies: Fix Resolution Without Adding Edges

In short: Find when a Gradle version constraint expresses policy without introducing a dependency into the graph.

Published 21 min read
On this page

Direct answer

A Gradle dependency declaration adds a module to the graph. A constraint only states a version requirement that applies when some other edge already pulls that module in. Pick a constraint when the goal is to record version policy for a module you never import directly. Pick a dependency when the build actually needs the artifact on a classpath. The concrete win is a version rule that cannot accidentally add a jar nobody uses. The concrete loss is that a constraint attached to a module which is absent does nothing, so the rule silently waits for an edge that may never arrive. The practical implication is that every proposed version change needs a graph reading before the edit, not a version guess afterward. Ask Claude Code to print the resolved graph before and after a candidate change, then to explain which declaration supplied each selected version.

Why a misplaced version costs an afternoon

Two failure modes come from putting version policy in the wrong construct. A direct dependency used purely to force a version drags the module onto every configuration that resolves, including ones where it was never needed. Reviewers see a new edge and cannot tell whether the build uses the artifact or merely wanted a number. The opposite mistake is a constraint written against a module no edge brings in. The constraint sits in the build logic, resolves to nothing, and the upgrade everyone expected never happens.

Both mistakes are quiet on a developer machine. Local resolution succeeds, tests compile, and CI reports green. The cost lands later as a duplicate library at runtime, a security review that cannot find the expected version, or an upgrade that two engineers believe is in place while the graph says otherwise. Reading the graph first turns a mystery into a diff.

Evidence and its limits

Official, F023: The Gradle guide on dependency constraints and conflict resolution documents constraints as version requirements that apply when the constrained module is part of the graph, and records that ordinary version conflicts select the highest requested version by default. Strict constraints, platforms and other resolution rules can change the outcome, so default behavior is not a guarantee.

Official: The page on declaring dependency constraints shows the constraint syntax and describes the difference between adding a module and constraining one that another declaration brings in.

Official: The dependency management overview and the dependency management basics page describe how configurations, resolves and version selection fit together for JVM builds.

Official: Declaring dependencies documents the notation forms used in the examples below.

Official, agent loop: Claude Code best practices recommends pairing an edit with a check that returns pass or fail. For version work that check is a resolved-graph diff.

Derived, F024: The placement table and the proposed-change review below are an editorial method built on those pages. They do not promise that every configuration in a real build resolves identically.

No claim here depends on a particular Gradle release number, a specific plugin version, or any benchmark.

Dependencies create graph edges

A dependency declaration names a module and, in almost every case, a version. During resolution that module becomes a node in the graph and the declaration becomes an edge from the configuration that requested it. Edges are what version selection walks. Remove the edge and the node has no reason to exist.

Property Dependency declaration Version constraint
Adds a module to the graph Yes No
Provides an artifact Yes No
Supplies a version when absent Yes, its own No effect
Influences selection when present Yes, as a request Yes, as a requirement
Reads as intent “We use this” “We require this version if used”
Typical home Application module, library that imports it Platform, shared build logic, root build

The distinction that matters for review is the first row. Any line whose only purpose is to change a version number should be examined for whether it needs to be an edge at all.

Constraints express version requirements

A constraint attaches a version requirement to a module coordinate. The requirement participates in version selection for that coordinate. If no declaration in the graph selects the coordinate, the constraint does not add it. Gradle’s own wording, captured in F023, is that constraints apply when the module is present.

Two flavors matter in review. A plain constraint participates with other requests, and the ordinary rule in F023 means the highest requested version wins in a conflict. A strict constraint narrows the outcome and can fail resolution rather than negotiate. A platform brings a set of constraints together so several coordinates can be governed from one place. Treat any existing strict or platform constraint as something the proposed change must be checked against, never overwritten casually.

Read the resolved graph

The resolved graph is the only evidence that a version rule did what the author intended. Two tasks produce it.

bash
./gradlew :app:dependencies --configuration runtimeClasspath
bash
./gradlew :app:dependencyInsight --dependency com.google.guava:guava --configuration runtimeClasspath

The first command prints the tree for one configuration. The second answers the question reviewers actually ask: which declarations requested this coordinate, and which version was selected. A tree line whose selection reason is “requested by” several edges is a conflict that default selection settled. A version that appears because of a constraint usually says so in the insight output.

Read the insight output before writing the fix, not after. Guessing that a version conflict exists is how a constraint gets added to a coordinate that was already governed by a platform, or how a dependency gets promoted to direct when the real problem was one stale transitive request.

Choose constraint placement

Placement decides which configurations see the rule. A constraint declared in a subproject applies to that project’s configurations. A constraint declared in a platform consumed by many projects applies wherever the platform is on the classpath. A constraint in root build logic may reach every subproject or none of them, depending on how the logic is applied.

Candidate placement Configurations reached Reachable from Watch for
Application module build script That module’s configurations Module reviewers Rule does not travel to other consumers
Shared convention plugin Every project that applies the plugin Platform team Broad blast radius on a typo
Java platform module Configurations that consume the platform Any consumer of the platform Consumers who never import the platform miss the rule
Root build for a single-project repo Project configurations Whole team Looks global but is only project-local

Record the intended reach in the same change that proposes the constraint. The record is what turns a review question from “will this affect everything” into “does this reach the two projects we agreed on”.

Review conflict selection

Once a candidate constraint exists, the review is a before-and-after comparison of the same insight command. Three outcomes are common.

Outcome Insight shows Meaning Action
No change Same selected version before and after Another request already exceeded the constraint Drop the constraint or raise it to matter
Expected bump New selected version, constraint listed as requester Constraint governed the coordinate Confirm no strict rule was overridden
Resolution failure Strict constraint conflict Existing rule contradicts the new one Negotiate in review, do not force

Highest-version selection, the default recorded in F023, is not a safety property. A newer version is not automatically the correct one, and a constraint that only wins because it is the highest number has not been reviewed.

Separate policy from usage

Version policy answers “which version are we willing to run for this coordinate”. Usage answers “which modules does this build import”. Keeping the two apart is what makes both readable.

Policy belongs in one place per coordinate, ideally a platform or a convention plugin that the team already reviews. Usage belongs in the module that needs the artifact. A build where policy is scattered across module scripts forces every reviewer to guess which declaration is authoritative.

Ask Claude Code to propose a placement table for a version change rather than a one-line edit. The Gradle capability conflicts guide covers the related question of two components claiming the same capability, and the Gradle variant attributes guide covers which artifact a consumer request selects once the coordinate is settled.

Explain the proposed change

A version proposal is complete when a reviewer can answer four questions without opening the build.

Question Where the answer lives Pass condition
Which coordinate changes Constraint or dependency line One coordinate, one line
Which configurations are affected Placement table Listed explicitly
What the graph showed before Insight output pasted into the description Selected version recorded
What the graph shows after Insight output pasted into the description Diff explained, no silent strict override

Paste both insight excerpts into the pull request. A description that says “bump guava” without the graph forces the reviewer to reproduce the work.

A worked walkthrough of one constraint

Consider a repository where com.google.guava:guava arrives transitively through three different libraries, each requesting a different version. Default selection, recorded in F023, picks the highest. A security review asks the team to guarantee at least 32.1.0 across the build.

The instinctive edit is a direct dependency on 32.1.0 in the application module. That works, and it also adds guava as a first-class edge to every configuration that resolves. Two quarters later nobody remembers whether the application imports guava, and removing it feels risky because the version might drop.

The constraint version of the same intent looks different.

bash
dependencies {
  constraints {
      implementation("com.google.guava:guava:32.1.0")
  }
}

Nothing imports guava. The rule only participates when some edge selects the coordinate, which it does here. Running the insight task for guava before and after shows the same selected version in both, because the transitive requests already exceeded 32.1.0. That is the “no change” outcome from the conflict table, and it means the constraint is recording policy rather than changing the build. A reviewer can then decide whether the number should rise to matter or the constraint is documentation.

Contrast a case where the highest transitive request is 31.0. The same constraint moves the selected version to 32.1.0, and the insight output lists the constraint as the requester. Both diffs are correct outcomes. The point of the walkthrough is that the diff tells you which one happened, and the reviewer signs off on the actual outcome rather than the intended one.

Anti-patterns that look like constraints

Four patterns recur in version work, and each one hides intent that a reviewer needs.

Pattern What it looks like Why it hurts Do instead
Force in configurations.all resolutionStrategy.force on a coordinate Overrides everything, including intentional upgrades Use a constraint, or fix the requesting library
A direct dependency for a version implementation("x:y:1.2") used nowhere Adds an edge nobody uses Convert to a constraint
Version in two places Constraint plus a direct dependency Reviewers cannot tell which governs One construct per coordinate
Constraint in a module that never resolves it Constraint in a test module for a runtime coordinate Rule never applies Move it to the platform or convention plugin

Force deserves the most caution. A forced version wins regardless of what else requests, which is occasionally correct and usually a rule that outlives its reason. When a force is genuinely required, the change description should say why every other request loses, because that is the claim a reviewer has to evaluate.

None of these patterns is a Gradle defect. They are review hazards, and the placement table plus the insight diff are what catch them.

A runbook for the next version request

The checklist earlier in this post is the pass condition. The runbook below is the sequence to follow when a request arrives.

Record the coordinate and the intended version. The coordinate is the review key, and a request without one is a request to guess.

Run the insight task for the coordinate on every configuration the placement table names. Paste the output into the request. This is the before state, and it is the evidence the whole review rests on.

Decide the construct. If the build imports the artifact, it is a dependency. If nothing imports it and the intent is version policy, it is a constraint. Write the decision into the request so the reviewer does not re-derive it.

Apply the edit and run the insight task again. Compare the two outputs. A version that moved when you expected it to stay, or stayed when you expected it to move, is the finding to investigate before merging.

Name any strict rule or platform the coordinate already has. F023 lists strict constraints and platforms as things that alter the outcome, so a change that touches a governed coordinate needs that context in the description.

The runbook takes minutes and produces the two artifacts a reviewer needs: the placement table and the before-and-after diff. Skipping it produces a one-line change that the reviewer has to reproduce from scratch.

Where this habit pays across the batch

The evidence-first habit in this post is the same one the rest of the batch applies to different constructs. Gradle capability conflicts asks for a component inventory before a resolution strategy, and Gradle variant attributes asks for the consumer request before a notation change. Maven optional dependencies asks for an import scan before a declaration.

The .NET posts apply the same discipline to package versions. NuGet central package management asks for a props and override inventory before centralizing, and .NET multi-targeting asks for a per-framework build before calling a version supported. C# source generators asks for the generator’s input change before reading its output.

The C++ posts apply it to configure inputs and dependency boundaries. CMake presets asks for the resolved preset inputs before a configure, CMake find_package vs FetchContent asks for a resolution trace before choosing a path, and Conan CMakeDeps asks for the target contract before a layout change.

That consistency is deliberate. The constructs differ, but the shape is the same: read the evidence the tool already produces, then make the smallest change the evidence supports.

The same shape extends to the ecosystems covered in earlier batches. On the Python side, dependency groups versus extras separates local workflow requirements from published optional features, and stub drift audits a package’s declared types against its documented runtime surface. TypedDict boundaries covers separating truly optional keys from missing data before replacing broad dictionary annotations.

On the Go side, module compatibility covers keeping an exported API change inside an import contract, and graph pruning covers why an indirect dependency entry is graph metadata rather than something to delete. Workspace boundaries covers deciding what belongs in go.work versus what stays a module requirement.

On the Rust side, feature unification covers mapping which optional APIs a workspace build actually exposes, and workspace inheritance covers centralizing metadata without hiding crate-local exceptions. Profile boundaries covers separating diagnostic and optimization settings from options that change observable program behavior.

Each of those posts applies the identical review discipline to a different manifest or graph. The evidence differs; the habit does not.

Working alongside the review bottleneck

A version change with a pasted diff is cheap to review. A version change without one is a reviewer reproducing the work, and reproduction is the expensive part. The Claude Code code review bottleneck covers what happens when generation outpaces the review that has to accept it, and a paste-ready diff is the cheapest way to keep a version change on the cheap side of that line.

The same reasoning appears in Claude Code cost per verified change, which treats verified work as a separate unit from generated output. An insight diff is a verified unit. A “trust me, it bumps the version” description is not.

When the review queue is long enough that verification slips, the failure mode is a merge that nobody actually checked. Prevent false success from passing tests covers the case where a green build is the only evidence, and a resolution change is exactly the case where green proves less than it appears to.

The concrete win, loss, and implication

The concrete win is a version rule with no side effects. A constraint on a coordinate that only transitively appears cannot leak a jar into a configuration that never needed it, and the diff that introduced the rule is reviewable line by line.

The concrete loss is silence. A constraint whose coordinate is absent produces no warning, no failure, and no artifact. Teams have merged version policy that did nothing for months because the coordinate was renamed upstream. The mitigation is the insight check from the worked example, run on the configurations the placement table names.

The practical implication is that graph evidence belongs in the change, not in the reviewer’s head. Teams that paste resolved-graph excerpts into every version change resolve fewer “why is this version here” questions later. Teams that rely on memory re-litigate the same coordinate every quarter.

The same evidence-first habit appears across the JVM posts in this batch. Maven optional dependencies covers the consumer-side question of which optional libraries need direct declarations.

Resolution questions rarely stop at one construct. The .NET multi-targeting guide covers keeping framework-specific package versions visible beside shared source, and NuGet central package management covers the closest-props-file rule that decides which central version wins.

For C++ builds, the CMake presets guide covers making configure inputs explicit, and the CMake find_package vs FetchContent guide covers choosing a dependency boundary. The Conan CMakeDeps guide covers keeping consumer target names stable while layout changes.

Review and verification habits sit upstream of every version edit. Ask what Claude Code verification requires before calling a resolution change done, and prevent false success from passing tests when the only check is a green build. A change that also reformats build files is the pattern the Claude Code overengineering guide warns about.

For the cost side of repeated review work, Claude Code cost per verified change treats verified work as a separate unit from generated output, and Claude Code code review covers what happens when proposals arrive faster than review can accept them.

Evidence map showing a dependency declaration adding a graph edge while a constraint only records a version requirement for a coordinate another edge brings in.
Editorial evidence map based on F023 and F024. A constraint governs a coordinate without adding it; the labels are the post author’s, not a Gradle UI capture.

Checklist before merging a version change

Run this list against the diff. Each row is a pass condition.

Check Pass condition If it fails
Construct choice Constraint used when no direct usage exists Convert to a constraint or justify the edge
Placement table Affected configurations listed Complete the table first
Before graph Insight output recorded Run the insight task and paste it
After graph Insight output recorded Run the insight task and paste it
Strict and platform rules No existing strict rule silently overridden Negotiate in review
Highest-version reasoning Not used as the only justification Add the actual reason
Single coordinate One coordinate per proposal Split the change
Workflow from reading the resolved graph, through choosing a construct and placement, to a before-and-after insight diff.
Editorial workflow derived from F023 and F024. The sequence describes a review routine; it does not replace Gradle’s own conflict-resolution rules.

Working with Claude Code on version changes

Give the agent three inputs: the coordinate, the intended version, and the configurations the rule should reach. Ask for the insight output before the edit and again after. The agent session works best when the check is a command that returns pass or fail, which is the shape the official best-practices guidance recommends.

Ask the agent to report three things when it finishes. The construct it chose and why. The configurations the placement table names. The before-and-after insight diff. A report that omits the diff has not finished the task, because the graph is the only evidence the rule did anything.

Reviewing the construct choice is the reviewer’s job. The agent reads build files and can run insight, but deciding whether a coordinate is policy or usage is a design decision. The Claude Code verification guide covers the review questions: what changed, what proves it, and what was not checked.

Tradeoff between a side-effect-free constraint that waits silently for an edge and a direct dependency that always adds a module.
Editorial tradeoff diagram based on F023 and F024. The constraint avoids an unwanted edge at the price of silence when the coordinate is absent.

Data gap and future update

F023 describes default conflict behavior and names strict constraints, platforms and other resolution rules as things that can alter the outcome. This post does not enumerate every rule or version the behavior across Gradle releases. A future update should record, per project, which strict and platform rules exist for the coordinates the team constrains most often, plus the Gradle version those observations were taken at.

No benchmark, build-time measurement, or resolution-performance claim is made here. The effect of a constraint on build duration is out of scope and would require a separate measurement pass.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.

FAQ

Does a constraint add the module it names?

No. F023 records that constraints are version requirements for a coordinate that is already selected by some edge. A constraint on a module nothing pulls in does not introduce that module, which is the whole reason to prefer a constraint for pure version policy.

When should I use a direct dependency to change a version?

Only when the build actually uses the artifact. A direct dependency is an edge, and an edge travels to every configuration that resolves it. Using a direct dependency purely to force a number hides the intent and adds a module reviewers have to justify.

What is the difference between a constraint and a strict constraint?

A plain constraint participates in version selection alongside other requests, and F023 records that ordinary conflicts default to the highest requested version. A strict constraint narrows the outcome and can fail resolution rather than negotiate. Check for existing strict rules before adding either.

Why did my constraint change nothing?

Either the coordinate is absent from the configurations the placement table names, or another request already selected a higher version. Run the insight task for that coordinate on the affected configuration. The insight output names the requests and the selected version, which tells you which of the two cases you are in.

Is highest-version selection safe?

It is a selection rule, not a safety property. F023 records it as the default for ordinary version conflicts, and the default can be altered by strict rules and platforms. Review the reason a version was chosen, not just the number.

This post is one of ten build-system and dependency guides written together. Gradle Capability Conflicts covers resolving competing components, and Gradle Variant Attributes covers matching a consumer to the right artifact. Maven Optional Dependencies covers keeping transitive expectations explicit for consumers.

The .NET posts cover version and framework boundaries. NuGet Central Package Management covers cross-project version centralization, .NET Multi-Targeting covers per-framework package versions, and C# Source Generators covers reviewing generated contracts.

The C++ posts cover build inputs and dependency boundaries. CMake Presets covers reproducible configure inputs, CMake find_package vs FetchContent covers choosing a dependency boundary, and Conan CMakeDeps covers keeping consumer targets stable.

More from this batch

More Claude Code troubleshooting

Sources

Control checklist covering construct choice, placement table, before and after insight output, and strict rule review for a version change.
Editorial control checklist derived from F023 and F024. Passing the checklist shows the change was reviewed against graph evidence, not that every configuration resolves identically.
Verdict that a constraint placed where the coordinate is actually selected fixes resolution without adding a graph edge, while an absent coordinate leaves the rule silent.
Editorial verdict based on F023 and F024. A version rule backed by insight evidence is reviewable; an unverified constraint may be doing nothing.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →