gradledependency-managementgradle-dependencies

How can I force Gradle to redownload dependencies?


How can I tell Gradle to redownload dependencies from repositories?


Solution

  • Option 1: Use --refresh-dependencies flag

    Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies.

    Note that --refresh-dependencies won't always re-download every artifact; it will use existing copies if they match what exists in the repository. From the Gradle User Guide, refreshing dependencies:

    The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts. A fresh resolve will be performed against all configured repositories, with dynamic versions recalculated, modules refreshed, and artifacts downloaded. However, where possible Gradle will check if the previously downloaded artifacts are valid before downloading again. This is done by comparing published SHA1 values in the repository with the SHA1 values for existing downloaded artifacts.

    [...]

    It’s a common misconception to think that using --refresh-dependencies will force download of dependencies. This is not the case: Gradle will only perform what is strictly required to refresh the dynamic dependencies. This may involve downloading new listing or metadata files, or even artifacts, but if nothing changed, the impact is minimal.

    Option 2: Remove ~/.gradle/caches

    You can also delete the cached files (artifacts and metadata) under ~/.gradle/caches. With the next build Gradle will attempt to download them again.

    On *nix systems (Linux, macOS, ...), you can execute this command:

    rm -rf $HOME/.gradle/caches/
    

    After doing this, you might also need to kill the running Gradle Daemon:

    ./gradlew --stop