Gradle re-execute tasks due to alleged JAR dependency change

@sterling @Stefan_Wolf Sorry for being reluctant to generate that list, but it would be problematic for me to prepare it in a proper form and in fact I am skeptical that it will be useful (it’s just hundreds of open source libs and some internal stuff). Therefore, as an alternative, I analyzed the outputs and I have found some interesting corelation.

The builds are they are identical (omitting negligibly different task time executions) up until one place:

Selected primary task 'theTaskICall' from project :
Creating new cache for metadata-2.23/module-versions, path /home/foo/.gradle/caches/modules-2/metadata-2.23/module-versions.bin, access org.gradle.cache.internal.DefaultCacheAccess@74ba7c0f
Creating new cache for annotation-processors, path /home/foo/my-project/.gradle/4.0.1/fileContent/annotation-processors.bin, access org.gradle.cache.internal.DefaultCacheAccess@31854e8a

In a subsequent build which triggers task execution (by having different classpath) the order of caches creation is reversed:

Selected primary task 'theTaskICall' from project :
Creating new cache for annotation-processors, path /home/foo/my-project/.gradle/4.0.1/fileContent/annotation-processors.bin, access org.gradle.cache.internal.DefaultCacheAccess@57ee440b
Creating new cache for metadata-2.23/module-versions, path /home/foo/.gradle/caches/modules-2/metadata-2.23/module-versions.bin, access org.gradle.cache.internal.DefaultCacheAccess@53eb01e3

I run several builds one by one to confirm that and only if the order has changed since the last execution the tasks were considered not up-to-date. I could have 6 executions in the same order in a row (one variant), a change (causing a task re-execution) and another few builds in the 2nd variant (without task re-execution).

It allows me to suspect that there could be some race in Gradle and the order of cache creation implies different classpath order (at least in some kind of builds). WDYT?

Btw, the build was executed without build cache enabled and with sequential task order (without the --parallel flag).