Safeguard
Developer Tools•

Maven or Gradle: which pinning controls should I use?

A decision table for Java dependency pinning: dependencyManagement, BOMs, Enforcer, Gradle constraints, locking and verification, and what each controls.

Safeguard Security Team
3 min read

Use a version source (a BOM, dependencyManagement or a catalog) to choose versions, a lock or Enforcer rules to keep them from drifting, and verification to prove the files are what you expect. No single control does all three jobs, and none replaces vulnerability scanning.

Definitions

Pinning means making the version that resolves a deliberate choice rather than an accident. There are three separate questions:

  1. Which version do we want? A decision about versions.
  2. Does the build resolve exactly that? A repeatability check.
  3. Is the downloaded file genuine? An integrity check.

Decision table

ControlBuild toolAnswersDoes not answer
dependencyManagement and BOM importsMavenWhich version, for direct and transitive artifactsWhether it drifts, or whether the file is genuine
Enforcer rulesMavenWhether versions converge, stay at upper bounds, avoid banned artifactsWhich version is safe
Exact versions, no rangesMavenRepeatability for that artifactTransitive drift
Dependency constraintsGradleWhich version, including transitiveWhether the file is genuine
Version catalogsGradleOne place to declare versionsThey are requests, not guarantees
Dependency lockingGradleWhether resolution matches a committed lockWhich version is safe
Dependency verificationGradleWhether files match recorded checksumsWhich version is safe
Wrapper checksumGradleWhether the Gradle distribution is genuineAnything about your libraries

Read the details here: Maven BOMs, Maven mediation, Maven Enforcer, Gradle catalogs, Gradle locking, Gradle verification, wrapper checks.

A sensible baseline for each tool

Maven

  1. Manage versions in a parent POM or imported BOM.
  2. Replace version ranges with exact versions.
  3. Add dependencyConvergence and requireUpperBoundDeps to Enforcer.
  4. Set checksumPolicy to fail on repositories you declare, see Maven ranges and checksum policy.

Gradle

  1. Declare versions in a catalog.
  2. Add constraints for transitive fixes.
  3. Turn on locking and commit the lockfile.
  4. Add dependency verification and wrapper checksum.

Which to do first

If you can do only one thing this week, make the version choice explicit and reviewed. Everything else builds on that. The second step is repeatability, then integrity.

Where scanning fits

None of these controls tells you whether a version has a known vulnerability. Scanning runs against the result. The pinning controls make scan results stable, and the scan decides which pins to change.

Try it yourself

Click through it at your own pace, or open it full screen.

See how a pull request can be held until a policy passes. That is the review point for any version change.

Where Safeguard fits

Safeguard offers dependency scanning and SBOMs, and policies and gates that can block changes carrying known vulnerable versions. Try the free scan.

Quick check

Does a lockfile make my dependencies safe?

No. It makes them repeatable. A locked version can still be vulnerable.

Do I need both a BOM and Enforcer in Maven?

They do different jobs. The BOM chooses versions, and Enforcer fails the build when the tree breaks your rules.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.