Old build.gradle file version sometimes used


(Martin Vysny) #1

Hello! I’m stuck with a really weird issue, and I’d like to hear your opinion on this.

I’m using Gradle 4.7. I am typically editing the build.gradle file from Intellij, while having the Gradle auto-import setting turned on. However, on a couple of occasions a strange error occurred, as if the Gradle remembers older version of the build file and stubbornly uses that one.

For example, say I’m editing a dependency in my build.gradlefile, say: compile 'org.slf4j:slf4j-api:1.7.24'. To upgrade that to version 1.7.25 I press backspace to remove the 4 so and type in 5. The file now looks like compile 'org.slf4j:slf4j-api:1.7.25'; however when I do ./gradlew clean build Gradle fails that it can’t download slf4-api:1.7.2.

Workaround is to add any characters, say, a meaningless comment - then Gradle uses the correct file and the gradle script works. If I remove the comment and revert the gradle file back to slf4j-api:1.7.25, then Gradle reverts back to using slf4-api:1.7.2 and fails.

It looks to me as if Gradle ‘remembered’ the build.gradle file in a state when the dependency was slf4-api:1.7.2, but under a hash of the build.gradle file which reads slf4-api:1.7.25.

Since the error happens at random and is really hard to reproduce, I do not know whether I should open a bug report, therefore I’m asking on the forums first. Thanks! :slight_smile:


(Martin Vysny) #2

Disabling the build cache with --no-build-cache does not seem to help. The situation is only fixed when I remove the ~/.gradle directory. After the issue occurs, it is 100% reproducible, and it’s reproducible even outside of Intellij, when calling command-line ./gradlew script. This leads me to believe that this is some kind of race condition in the Gradle itself. I’m using Gradle 4.7.