How to let Gradle fail when `gradlew dependencies --write-locks` fails

I publish some open-source librarires to Maven Central, which have dependencies to another library of mine.

Sometimes ./gradlew dependencies --write-locks fail inside because an expected dependency is not ready on Maven Central, but the entire Gradle command still succeeded. It did not “fail” even if ./gradle dependencies --write-locks included FAILED. I sometimes overlooked such FAILED inside, gone ahead, and notified a problem in a later step.

Q. How can I let the entire ./gradle dependencies --write-locks command fail when it includes FAILED?

The dependencies task never fails the build just because of failed dependencies.
It is a reporting task that intentionally does not fail the build but displays the dependencies and their versions and whether they could be resolved.

The --write-locks option just locks all versions of locked configurations that are resolved during the current build. The dependencies task is a cheap way to do that, but it has drawbacks. One is, that you do not get a failure, another is, that it is not executed in all projects if you have a multi-project build.

If you want the build to fail, I recommend using the alternative way documented at Locking dependency versions where you add an own task that resolves all resolvable configurations and thus locks them if --write-lock is given. As this task then does not do lenient resolution like the dependencies task, it should fail on resolution errors.

1 Like

Thanks! It sounds reasonable that dependencies is designed to be just a reporting task that intentionally does not fail. I see…

Sure. Let me try having my own task to do that.