I tried to collect any artifact that is used by gradle to resolve the dependencies (incl. transitive dependencies). If we have for example a dependency to “commons-logging” (compare the code below), then gradle is downloading the pom of commons-logging and the
parent-POM. I have implemented a DependencyResolutionListener to get a notification, if a dependency was resolved. The resolved dependencies contains a reference to the JAR-file, but I did not see currently a way to get a list of all POMs, that are used by gradle to resolve dependencies. Does anybody knows a way how to get a list of all POMs?
apply plugin: 'java'
apply plugin: 'maven'
repositories {
maven { url "http://localhost:8080/artifactory/repo"
}
}
dependencies {
compile (group: 'commons-logging', name: 'commons-logging', version: '1.1.1')
}
task resolveDependency << {
def listener = new DependencyResolutionListener() {
void
afterResolve(ResolvableDependencies dependencies) {
println "afterResolve: " + dependencies
dependencies.dependencies.each {
it.artifacts.each {
println "resolved artifact: " + it.name + "." + it.classifier + "." + it.extension + "." + it.type + ":" + it.url
}
println "resolved dependency: " + it
}
dependencies.files.each {
println "dep.file: " + it
}
}
void
beforeResolve(ResolvableDependencies dependencies) {
println "beforeResolve: " + dependencies
}
}
project.getGradle().addListener(listener)
def configuration = project.configurations.getByName('compile')
def artifacts = new HashSet()
configuration.resolvedConfiguration.firstLevelModuleDependencies
}
Output of the script above with an empty gradle cache.
:resolveDependency
beforeResolve: dependencies ':compile'
Download http://localhost:8080/artifactory/repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download http://localhost:8080/artifactory/repo/org/apache/apache/4/apache-4.pom
afterResolve: dependencies ':compile'
resolved dependency: DefaultExternalModuleDependency{group='commons-logging', name='commons-logging', version='1.1.1', configuration='default'}
Download http://localhost:8080/artifactory/repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
dep.file: /home/haasm/.gradle/caches/artifacts-14/filestore/commons-logging/commons-logging/1.1.1/jar/5043bfebc3db072ed80fbd362e7caf00e885d8ae/commons-logging-1.1.1.jar
BUILD SUCCESSFUL