Gradle plugin's configurations are missing dependencies


(Bobak) #1

Hi guys.

I’m building gradle plugin. I need to get list of all dependencies during plugin’s execution phase for further processing. Unfortunately whatever I do, I always get only test.jar as dependency from whatever configuration.
Code I’m usign for retrieving list of jars :

List dependencies = Lists.newArrayList();

for (Configuration configuration : project.getConfigurations()){
for (File dependencyFile : configuration.getAllArtifacts().getFiles()){
if (isJar(dependencyFile) || dependencyFile.isDirectory()) {
dependencies.add(dependencyFile);
}
}
}

My build.gradle :

group = 'net.insomnia.gradle.yang2source’
version = '1.0.0-SNAPSHOT’
apply plugin: 'groovy’
apply plugin: 'maven’
apply plugin: ‘java’

repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
url “https://nexus.opendaylight.org/content/repositories/public
}
maven {
url “https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot
}
}

dependencies {
compile gradleApi()
compile 'org.slf4j:slf4j-api:1.7.21’
compile 'com.google.guava:guava:19.0’
compile 'commons-io:commons-io:2.0.1’
compile 'org.opendaylight.yangtools:yang-model-api:1.0.0-SNAPSHOT’
compile 'org.opendaylight.yangtools:yang-parser-impl:1.0.0-SNAPSHOT’
compile 'org.opendaylight.mdsal:maven-sal-api-gen-plugin:0.9.0-SNAPSHOT’
compile 'plexus:plexus-logging-provider-test:1.0-alpha-1’
runtime 'net.insomnia.yang.dependencies:yang-dependencies:1.0.0-SNAPSHOT’
compile ‘org.sonatype.plexus:plexus-build-api:0.0.7’

testCompile 'junit:junit:4.12'
testCompile gradleTestKit()

}

uploadArchives {
repositories {
mavenDeployer {
repository(url: “file://~/.m2/repository/”)
}
}
}


(Stefan Oehme) #2

Configurations serve a sometimes confusing double purpose: Defining artifacts that get built and their dependencies. What you want is configuration.getFiles() (the dependencies of this configuration), not configuration.getArtifacts() (the artifacts created by this configuration).