Force resolving (and downloading) all dependencies


We are running a CI build of some of our Gradle applications. These builds are run inside Docker containers in an ‘empty’ system. To improve build times, we cache the dependencies of the Gradle home folder (the wrapper and caches directories).

Summarized, the build is split up into many modules in the following way:

  1. Caching:
    • Fetch the cache
    • Install any dependencies not in the cache (*)
    • Store the cache, if anything has been updated
  2. In parallel (for every module, around 40):
    • Restore the dependency cache
    • Build the module
    • Run the tests
  3. Report test results

The question is how to resolve all dependencies for all modules, for all configurations (the (*) step). We have tried the dependencies task, but this only resolves the compile dependencies. We have also tried the test task with a filter not maching any tests, but Gradle will fail because no tests are run. We have also tried enabling dependency locking, but this made no difference.

How to force resolve (and download) all dependencies for all configurations without running any actual tasks?

Thanks in advance!


I have solved a similar use case.
The following script provides a task that can leverage the incremental task support of Gradle, without resolving configurations for other tasks (thanks to the task configuration avoidance api).

allprojects {
    tasks.register("downloadDependencies", Copy) { Copy copy ->
        copy.into project.layout.buildDirectory.dir("dependencies")
        copy.from {
            configurations.matching { Configuration c ->
            }.collect { Configuration c ->

The dependency verification feature of Gradle does something like that internally, when calling --write-verification-metadata.

Note, however, that as the documentation explains, it’s an approximation of what dependencies could be downloaded during a build. In particular, if a task uses what we call a “detached configuration” (a dynamic dependency graph at execution time), then those dependencies will not be downloaded, because they are opaque to Gradle.

Thank you both for the answers. This helped me and the results look promising!

@CedricChampeau It seems that dependency verification is only added in Gradle 6? I could not find that documentation for version 5.

Dependency verification was introduced in Gradle 6.2: