How can I force update all the snapshot Gradle dependencies in intellij

84,698

Solution 1

I have run into some very sticky snapshots. There are a few options you can try:

  • On the Gradle tab (right side of UI), click the blue circling arrows icon, which should refresh the dependencies (works in most cases)
  • If that does not work, try running the gradle command in IntelliJ using the Green "run Gradle command" icon - this runs the command in IntelliJs environment not that of your local machine.
  • If both of those fail, you can modify your Gradle resolutionStrategy settings to something like: configurations.all { resolutionStrategy.cacheDynamicVersionsFor 4, 'hours' resolutionStrategy.cacheChangingModulesFor 4, 'hours' } This config change is a last-ditch option and should be used sparingly. It basically tells Gradle to refresh the local cache more often. You should click the IntelliJ Gradle refresh button after making these changes.

Solution 2

In IntelliJ 2017.2 you can right-click on the project name in the Gradle Tool Window and select Refresh dependencies from the context menu.

Refresh Gradle dependencies in IntelliJ 2017.2

This will refresh all your dependencies, not only the SNAPSHOTS, so it might take a while. I don't know if other versions of IntelliJ also have this feature.

Solution 3

Another option is to open up the Project Structure, and under Project Settings, Libraries, find the dependency in the list and remove it. Then press the Gradle refresh blue circling arrows icon and IntelliJ should fetch the latest version.

enter image description here

enter image description here

Solution 4

IntelliJ IDEA ULTIMATE 2020.1

Right-click on the project name in the Gradle Tool Window and select Refresh Gradle Dependencies from the context menu.

enter image description here

Solution 5

EDIT

On Gradle 6+, snapshots are changing by default. So, no need to set changing = true anymore.


Previous answer:

Gradle caches changing modules for 24 hours by default. We can tell Gradle to refresh or redownload dependencies in the build script by marking those as 'changing'.

Follow these steps:

Step #1: Tell Gradle not to cache changing modules by set the value of the cacheChangingModulesFor property to 0 second:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Step #2: Mark dependencies which are needed to be refreshed or redownloaded, as changing module:

dependencies {
    implementation("com.howtoprogram.buysell:payment-api:0.0.1-SNAPSHOT") {
        changing = true
    }
}

Source: Refresh or Redownload Dependencies in Gradle

Share:
84,698

Related videos on Youtube

Vad1mo
Author by

Vad1mo

In codice veritas!

Updated on September 03, 2021

Comments

  • Vad1mo
    Vad1mo over 1 year

    I have a project with SNAPSHOT dependencies using gradle as its build tool in intellij.

    The problem is that intellij is using SNAPSHOTS that are now outdated. enter image description here

    When I build the project on the command line

    gradle build or 
    gradle clean build --refresh-dependencies
    

    On command line the latest dependencies are fetched. I also setup my grade file to always download snapshot dependencies according to this answer.

    How can I force intellij to download all dependencies?

  • cjstehno
    cjstehno almost 6 years
    On the Gradle tab in Intellij there is a green icon along the top that will allow you to execute a gradle command in the IDE.
  • elect
    elect almost 6 years
    Ah, I got what you meant, and then? gradle clean build --refresh-dependencies?
  • Sousou about 5 years
    This works but it is very slow. Does anyone know how to optimize to only get the latest SNAPSHOTS?
  • Miloš Černilovský
    Miloš Černilovský over 4 years
    This was the only solution that worked for me, after trying the other answers (maybe it needs to be done after the --refresh-dependencies solution).
  • Kevvvvyp almost 2 years
    If you are uploading the snapshots then appending the commit number if a quick fix... 1.0.0-SNAPSHOT-1
  • Jilles van Gurp
    Jilles van Gurp almost 2 years
    the property is called isChanging on 6.8.x in kts dialiect. But seems to be a thing. Would be nice if they did that automatically for snapshot builds.
  • Gilberto Ibarra
    Gilberto Ibarra over 1 year
    This dont work if the snapshot have changes and have the same version.
  • Louis CAD
    Louis CAD over 1 year
    @JillesvanGurp Well, that's the case since Gradle 6, see the edit.
  • Jilles van Gurp
    Jilles van Gurp over 1 year
    Yes, the caveat is that it only checks every 24 hours unless you change that to something more reasonable. We ended up configuring a configurations.all { resolutionStrategy { cacheChangingModulesFor(60, TimeUnit.SECONDS) } } to work around that.
  • Wirat Leenavonganan
    Wirat Leenavonganan 11 months
    Many thanks. Struggle on this several hours.