How to get checksum (sha1) for a cached resource (or artifact)


(harshad_penkar) #1

I can iterate files that are part of my configuration by using:

task listJars << {
    configurations.compile.resolvedConfiguration.resolvedArtifacts.each { artifact ->
        println artifact
    }
}

This tells me details like artifact group, name, version, ext, type etc. I also need sha1 value of the artifact. I looked at the absolutePath and here is absolutePath of one of the files in cache:

c:\home\.gradle\caches\artifacts-15\filestore\com.xxx\ant\1.8.4\jar\8acff3fb57e74bc062d4675d9dcfaffa0d524972\ant-1.8.4.jar

Based on the absolutePath of the file I can verify that the magic numbers (8acff3fb57e74bc062d4675d9dcfaffa0d524972) preceding the jar name are the sha1 values maintained in Artifactory. Are there any APIs exposed to get the sha1 value? Can I always rely on the absolutePath to derive the sha1 value (or this path would be internal to gradle and may change in future)?

Thanks, -Harshad.


#2

Can I always rely on the absolutePath to derive the sha1 value (or this path would be internal to gradle and may change in future)?

There is no guarantee that this path won’t change: it’s just a convenient way for Gradle to store artifact files.

Are there any APIs exposed to get the sha1 value?

Not anything that’s considered part of the public API. But you may have luck with org.gradle.util.hash.HashUtil. There’s no guarantee that it won’t change in the future, but you could very easily copy-paste your own implementation.