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

(remy) #1

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:’’: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)


(kellyrob) #2

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

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

How to only build and cache modified dependencies without completely building?
(Szczepan Faber) #3


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

(remy) #4

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( && 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


} }