How to get absolute path of a file declared in dependencies?

Hi gradle experts,

I have a gradle project with a runtime dependency such as:

dependencies {

//DB dump file for current project

runtime ‘com.mycompany.db:’+project.name+’:TRUNK-SNAPSHOT’ }

The dependency is an DB dump file.

At runtime, the dependency is resolved and a file is downloaded from repository server and put into gradle cache directory, such as: $GRADLE_HOME/caches/artifacts-14/filestore/com.mycompany.db/myprojectl/TRUNK-SNAPSHOT/dmp/myprojectl-TRUNK-SNAPSHOT.dmp

I would like to write a gradle task to invoke an external process to import the dump file into a local DB. To do so, an external process will be invoked from gradle (impdp) and it will need to get the full path of the dump file.

Any idea on how to retrieve the full path of a file defined in runtime dependency? (this is similar to what is done in gradle eclipse to generate eclipse .classpath/classpathentry/sourcepath)

Thanks!

You can get the paths of all files in a configuration by calling the Configuration.resolve() method.

repositories{
 mavenCentral()
}
configurations{
 runtime
}
dependencies {
 runtime 'commons-lang:commons-lang:2.6'
}
  println configurations.runtime.resolve()

Alternative:

task printDeps {
  doLast {
     println "Dependencies:"
     configurations.runtime.each { println it }
  }
}

Thank you very much!

Here is the updated code with the condition to only get a specific artifact:

task viewdump << {

println “Dependencies:”

configurations.runtime.resolve().each {

String absolutPath=it.getAbsolutePath();

if(absolutPath.contains(“com.mycompany.db”) && absolutPath.contains(project.name) && absolutPath.contains(“TRUNK-SNAPSHOT”) && absolutPath.endsWith(".dmp")){

//full path for DB dump file for current project

println absolutPath

//call external process to import dump file

}

} }