Gradle Check Unused Dependencies

Dec 19, 2017 gradleLint.rules += 'unused-dependency' The rule inspects compiled binaries emanating from your project’s source setslooking for class references, and matches those references to the dependencies that you have declared in your dependenciesblock. Specifically, the rule makes the following adjustments to dependencies. Plugin that provides task for discovering dependency updates Min Gradle version: 4.5. In a series of experiments run with the help of gradle-profiler, Square found that they could improve both IDE sync time (a critical indicator) and build time by removing some unused dependencies. The dependencies have been configured to come from a local installation of Nexus, which will then proxy various external repos as well as our own hosted repositories. Often, when running a simple task (or just calling 'gradle depenencies'), gradle will pause for a very long time (often up to 5 minutes) while it displays messages about.

Gradle Check Unused Dependencies

Our testsuite on Cloud Build was taking about ten minutes to run 700+ Java and 410+ JavaScript tests with every merge to master, so we considered using Kaniko cache to save the dependencies into a Docker image, but it felt that we might end up with stale dependencies, given that sanity checking the contents of a docker image is a nontrivial task. So, inspired by the cache implementation in Github Actions, we decided to save and restore our gradle and npm dependencies ($HOME/.gradle and $HOME/.npm) into GCS, by adding two additional steps to our cloudbuild.yaml:

To make this work, we created a persistent volume mapped to /home/cache to store the cached dependencies between build steps.

Gradle check unused dependencies download

./save-cache and ./restore-cache are quite straightforward:

Gradle Check Unused DependenciesGradle Check Unused Dependencies

We compressed both folders into .tgz files, and you may have noticed the additional timestamp. This helps to avoid accumulating unused dependencies, for example if we change versions of gradle or individual libraries.

If the timestamp is missing or the cache is too old, we skip the restore-cache step and recreate the whole thing from scratch.

Gradle Check Unused Dependencies Linux

Gradle Check Unused Dependencies

Gradle Check Unused Dependencies Types

This process saved us 2 minutes of execution time per build, and it helped us reassess the size of our container images (saved 30s) and how many steps we could run in parallel (around 3 minutes per build). In the end, we could reduce from ten minutes to almost five, but your mileage may vary. Let us know your own results at @koliseoapi.