import groovy.io.FileType
def path = gradle.getGradleUserHomeDir().getAbsolutePath() + "/caches/modules-2/files-2.1/"
println "path:" + path
def jarList = []
new File(path).eachFileRecurse(FileType.FILES) { file ->
if (file.getName().endsWith(".jar")) {
jarList << file
}
}
如上即可遍历cache中当前模块的jar文件
同理,修改path值即可遍历其他路径中的文件