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:
Caching:
Fetch the cache
Install any dependencies not in the cache (*)
Store the cache, if anything has been updated
In parallel (for every module, around 40):
Restore the dependency cache
Build the module
Run the tests
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?
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).
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.