Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve both the artifact file and the artifact metadata from gradle dependencies?

Tags:

gradle

I want to write a gradle build task to perform some artifact repo copying and reorg. I got this far:

apply plugin: 'maven'
apply plugin: 'maven-publish'

repositories {
  ...
}

configurations {
  ...
}

dependencies {
  ...
}

task doit << {
  configurations.each { configuration ->
    println configuration
    configuration.files.each { file ->
      println "  f=${file.path}"
    }
    configuration.dependencies.each { dependency ->
      println "  g=${dependency.group}"
      println "  i=${dependency.name}"
      println "  v=${dependency.version}"
      dependency.artifacts.each { artifact ->
        println "    x=${artifact.classifier}"
        println "    n=${artifact.name}"
        println "    u=${artifact.url}"
      }
    }
  }
}

What I can't get is a reference to the downloaded file within the dependency.artifacts.each() loop.

The best I can do is populate an array by going through the configuration.files, and then hope that my second set of loops over the artifact metadata goes in the same order as the files. I'm obviously missing something

Maybe there is some alternate way? What I really want is to generate a set of tasks, one per artifact, that will allow me to publish a new artifact with changed metadata items (i.e. group id, artifact id and version should change).

like image 947
Christian Goetze Avatar asked Oct 15 '13 23:10

Christian Goetze


1 Answers

You want to iterate over the resolved dependencies/artifacts, not over the requested ones. Something like:

configuration.resolvedConfiguration.resolvedArtifacts.each { artifact ->
    println artifact.moduleVersion.id.group
    println artifact.moduleVersion.id.name
    println artifact.moduleVersion.id.version
    println artifact.file
}
like image 200
Peter Niederwieser Avatar answered Oct 22 '22 23:10

Peter Niederwieser