How can I force gradle to redownload dependencies? – Dev

The best answers to the question “How can I force gradle to redownload dependencies?” in the category Dev.

QUESTION:

How can I tell gradle to redownload dependencies from repositories?

ANSWER:

If you are using a recent version of Gradle, you can use –refresh-dependencies option.

./gradlew build --refresh-dependencies

you can refer to the Gradle manual.

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.

ANSWER:

Generally, you can refresh dependencies in your cache with the command line option –refresh-dependencies. You can also delete the cached files under ~/.gradle/caches. With the next build Gradle would attempt to download them again.

What is your specific use case? Do you use dynamic dependency versions or SNAPSHOT versions?


On Unix systems, you can delete all the existing artifacts (artifacts and metadata) Gradle has downloaded using:

rm -rf $HOME/.gradle/caches/

ANSWER:

For MAC

./gradlew build --refresh-dependencies

For Windows

gradlew build --refresh-dependencies

Can also try gradlew assembleDevelopmentDebug --refresh-dependencies

ANSWER:

You can tell Gradle to re-download some dependencies in the build script by flagging the dependency as ‘changing’. Gradle will then check for updates every 24 hours, but this can be configured using the resolutionStrategy DSL. I find it useful to use this for for SNAPSHOT or NIGHTLY builds.

configurations.all {
    // Check for updates every build
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Expanded:

dependencies {
    implementation group: "group", name: "projectA", version: "1.1-SNAPSHOT", changing: true
}

Condensed:

implementation('group:projectA:1.1-SNAPSHOT') { changing = true }

I found this solution at this forum thread.