Generated JAR files & cache miss

Hi,

I’m having issues with JAR task while trying to use build cache. Following code snippet generates two .jar files with same content. Even though, both jars have identical content checksum of jar files differ. In my case, I add generated jar files to class path for compile task and that results in cache miss. Upon further investigation, i came across post which explains its possible for same JARs to have different checksum due to local file headers https://stackoverflow.com/questions/43993329/why-does-the-same-jar-file-have-different-hash-every-time-i-build-it. Does this behavior of JAR file have cascading effect on other tasks (like compile)? Any help on how to fix this?

   task jar(type: Jar) {
    ["1.jar","2.jar"].each {
        from "1.txt"
        archiveName it
        destinationDir projectDir
        ant.checksum file: archivePath
    }
}

$ diff 1.jar.MD5 2.jar.MD5
4412c3a1da337f5f7e05ee72cacd33a7 | 97fa0813b8b8207e2056b6021617cf46

Context:
I’m experimenting with gradle cache in play project and came across the scenario where compilePlayBinaryScala is always missing the cache. Upon investigation, i identified that we generate few JAR files locally and add it to classpath for compilePlayBinaryScala.

Hi Devi,

for Jar files added to the classpath we ignore the local file headers (ordering & file timestamps). So that should not have an effect on the compilation task. Please have a look at runtime classpath normalization in the build cache guide for further information.

Do you maybe have timestamps or versions in the manifest? Could you provide a reproducible example for the behavior?

For better diagnosing the cache miss, please have a look at the corresponding section of the build cache guide.

Cheers,
Stefan