Gradle build fails when dependency resolution would update lockfile
0 reputation · 08 Dec 2021, 00:51 UTC
0 reputation · 08 Dec 2021, 00:51 UTC
Our team wants a repeatable development environment using Gradle dependency locking so resolved dependency versions stay consistent across local machines and CI.
Gradle writes lockfiles recording resolved versions, repositories, and metadata. During a normal build, Gradle does not automatically regenerate these lockfiles; if resolution would change a recorded entry, the build fails unless the --write-locks flag is used. We need to know whether automatic lockfile refresh is supported in any Gradle version, or whether manual regeneration remains the only supported path.
Which Gradle versions support automatic lockfile regeneration during a standard build? Is --write-locks the only supported way to update lockfiles, or can this behavior be enabled through a configuration property?
33275 reputation · 08 Dec 2021, 10:09 UTC
No version of Gradle supports automatic lockfile regeneration during a standard build. The --write-locks flag is the only supported mechanism to update lockfiles; there is no configuration property or setting to enable automatic updates.
Dependency locking is designed specifically to prevent the "silent" updates that occur with dynamic versions (e.g., 1.+) or changing snapshots. If Gradle detects that the current resolution result differs from the recorded entries in the lockfile, it intentionally fails the build. This failure serves as a guardrail, ensuring that developers and CI environments use identical dependency graphs until a human explicitly decides to update them.
--write-locks.To resolve a build failure caused by a lockfile mismatch, follow these steps:
./gradlew build --write-locks
gradle.lockfile (or configuration-specific lockfiles) using your version control system to ensure the version jumps are expected.You can verify this behavior by adding a dynamic dependency to your build.gradle:
dependencies {
implementation 'org.apache.commons:commons-lang3:+'
}
Once a lockfile is created, any new release of commons-lang3 will cause subsequent ./gradlew build commands to fail until --write-locks is applied again.
Diagnostic Detail: Are you using a custom Gradle plugin that manages dependencies? Some third-party plugins may attempt to wrap resolution logic, which could mask or alter standard locking errors.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.