Safeguard
Supply Chain•

Gradle dependency locking or verification: which do you need?

Locking fixes which versions Gradle resolves. Verification checks the downloaded files are the ones you expected. Different jobs, and CI wants both.

Safeguard Security Team
4 min read

They answer different questions. Dependency locking pins which versions Gradle resolves, so builds are repeatable. Dependency verification checks the checksums or signatures of the files Gradle downloads, so a tampered artifact fails the build. For a mobile CI pipeline, locking prevents surprise upgrades and verification catches swapped files.

What locking does

Gradle's documentation explains the problem with dynamic versions. A declaration such as 5.+ can resolve to different versions over time, so builds can break unexpectedly. To get reproducible builds you lock versions. Gradle writes a gradle.lockfile, and its header says the file is expected to be part of source control. The documentation also notes Gradle will not write lock state to disk if the build fails, so an invalid state is not persisted.

Locking says nothing about whether the bytes behind a locked version are genuine. If a repository serves a modified file for the same version, the lock still passes.

What verification does

Verification records expected hashes in gradle/verification-metadata.xml. The documentation says that when the build downloads an artifact it computes the checksum, and if it does not match, the build fails instead of using the tampered file. It also says checksums verify integrity but not authenticity, while signatures verify authenticity but may use weak hashes, and for the strongest security you use both.

Side by side

QuestionLockingVerification
Stops a surprise new versionYesNo
Stops a swapped file at the same versionNoYes
Where it livesgradle.lockfilegradle/verification-metadata.xml
Change costUpdate on each upgradeUpdate on each upgrade
Covers pluginsPer configurationYes, plugins and libraries

Why mobile projects feel this more

Android apps pull a large tree of transitive libraries and Gradle plugins from public repositories. A plugin runs code in your build, with access to whatever the job can see, including signing material. That is a good reason to verify plugins as well as libraries. Our post on why dynamic versions are a bad idea in mobile releases covers the first half of the story.

A rollout plan

  1. Replace dynamic versions with fixed ones where you can.
  2. Generate lockfiles and commit them. Review the diff when they change.
  3. Generate verification metadata, bootstrap it carefully, and commit it. Treat the first bootstrap as trusting what you have now, and sanity check anything unfamiliar.
  4. Make CI fail on mismatch, not warn.
  5. Assign an owner for upgrades so the files do not rot into a rubber stamp.
  6. Rebuild from clean in CI regularly so you notice failures early.

Existing posts on bootstrapping verification safely go deeper.

Common trap

Teams update verification metadata automatically on every failure. That defeats the control. A failed check should be a person asking why the file changed.

Try it yourself

Open the demo and see how the dependency inventory lists each component with its version. That list is what locking pins and verification checks.

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

Where Safeguard fits

Safeguard adds SBOM and dependency scanning plus reachability analysis on top of locked versions, so you can tell which advisories matter. Try the free scan.

Quick check

If I use verification, do I still need locking?

Yes, if you want repeatable versions. Verification alone does not stop a version from changing when a new one is declared or resolved.

Do lockfiles go in version control?

Gradle's documentation says the lock file is expected to be part of source control.

Sources

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.