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.
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 {
compile("com.howtoprogram.buysell:payment-api:0.0.1-SNAPSHOT") {
changing = true
}
}
Source: Refresh or Redownload Dependencies in Gradle
I have run into some very sticky snapshots. There are a few options you can try:
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.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.
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.
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.
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.