How to get gradle to output dependency hash for each dependency

橙三吉。 提交于 2019-12-23 19:50:41

问题


I am seeing, for the first time in my life, a situation where

gradle compileJava check runs fine locally but when I try to run the same commands with bitbucket pipelines I get NoSuchClassDefError

I do gradle user-login-server:dependencies locally and on pipelines and the versions for the artifacts I suspect are identical

So the only explanation I can come up with is that the actual artifacts are different.

Hence: How can I force gradle to output the hash of every dependency so I can trackdown what's going wrong?


回答1:


You could loop across the jars and print out a hash like so.

task printDependencyHashes() {
    def hash = { File file ->
        def md = java.security.MessageDigest.getInstance('MD5')
        file.eachByte(1024 * 4) { buffer, len ->
            md.update(buffer, 0, len)
        }
        return md.digest().encodeHex().toString()
    }

    doLast {
        configurations.compileClasspath.each { println "${it.name}: ${hash(it)}" }
    }
}


来源:https://stackoverflow.com/questions/45248234/how-to-get-gradle-to-output-dependency-hash-for-each-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!