Safeguard
Developer Tools•

Do you need Gradle lockfiles before onboarding a dependency scanner?

You can scan without Gradle lockfiles, but results get exact once they exist. When to generate them, where they live and how to review the first commit.

Safeguard Security Team
3 min read

No, you do not need lockfiles to start, but they make results exact. Gradle dependency locking records the precise versions a project used, so a scanner can read facts instead of resolving ranges. For a legacy monorepo, generate lockfiles for the services you care about first, then expand.

What a Gradle lockfile does

The Gradle user guide describes a lockfile as a record of the exact versions of dependencies used in a project, allowing verification during builds for consistent results across environments and over time. It also says the file should be kept in source control so everyone uses the same versions.

For scanning, the effect is simple. With a lockfile the scanner reads a fixed list. Without one, it sees declarations such as dynamic versions, and the answer can change from one day to the next.

Where the files live

Lockfiles sit at the root of each project or subproject directory, with the build script itself getting its own separate lockfile. In a monorepo with sixty Gradle subprojects, that is up to sixty new files. Plan the review accordingly.

Should you generate them before scanning?

SituationRecommendation
Services built and shipped regularlyGenerate lockfiles; they also make builds repeatable
Services frozen but runningScan the manifest first; generate lockfiles only if you will rebuild
Dynamic versions widely usedGenerate lockfiles soon; findings drift without them
Build too old to runSkip; scan declarations and mark results approximate

Steps for the first lockfile commit

  1. Pick one active subproject as a pilot.
  2. Enable locking in the build configuration for that subproject, following the Gradle guide.
  3. Generate the lockfile on a clean machine or in CI, not on a developer laptop with a warm cache.
  4. Review the diff: the versions in it should match what runs in production. If they do not, you have found a drift problem before the scanner did.
  5. Commit the lockfile with a short note in the pull request about what it is.
  6. Repeat for the next ten subprojects, then script the rest.

Mistakes to avoid

  • Generating lockfiles with a different Java version than production uses. Some resolution can differ.
  • Committing lockfiles and then never updating them. A stale lockfile pins a vulnerable version quietly. Schedule regular regeneration, and make dependency update pull requests include the lockfile change.
  • Treating the lockfile as the fix. It records versions; it does not choose safe ones.

Explaining it to developers

Teams worry that locking will slow them down. The honest answer: it adds one file to review when dependencies change, and in return builds stop changing under them. Say that, and offer to do the first generation for them.

Where Safeguard fits

Safeguard's dependency scanning reads lockfiles and manifests, and autonomous remediation can open fix pull requests, which stays off by default with every category on Manual until your team turns it on. See https://gold.safeguard.sh/scan for a free scan.

Quick check

Do lockfiles help with transitive dependencies?

Yes. The lockfile records the resolved versions of the whole set, so transitive packages show up with exact versions.

Who should own lockfile updates?

The team that owns the subproject. A platform group can supply a script, but the owning team should review the change.

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.