How to get the information of transitive dependencies in a gradle task?

匆匆过客 提交于 2019-12-05 16:21:40

Finally, I figure it out with follow task

class Dep {
  String group
  String name
  String version
  String extention
  String classifier

  Dep(String group, String name, String version, String extension, String classifier) {
    this.group = group
    this.name = name
    this.version = version
    this.extention = extension
    this.classifier = classifier
  }
}

task collectAllDeps << {

  def deps = []
  configurations.each {
    conf ->
      conf.getResolvedConfiguration().getResolvedArtifacts().each {
        at ->
          def dep = at.getModuleVersion().getId()
          println at.getFile().getAbsolutePath()
          //          dep = dep1.getComponentIdentifier()
          println "$dep.group:$dep.name:$dep.version"
          deps.add(new Dep(dep.group, dep.name, dep.version, at.extension, at.classifier))
      }
  }

  def json = groovy.json.JsonOutput.toJson(deps)
  json = groovy.json.JsonOutput.prettyPrint(json)

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