List files for a given project


(Povl Kvols) #1

I’m working on a project, where I translate a bunch of old Ant files to Gradle.

One problem is that the old Ant scripts assumes that jar files being used in a project is simply kept in a jar directory in the project.

Not any more though, since I try to use dependency management.

This gives a problem with some of the other projects, since their Ant scripts copy files from projects they depend on, in order to create jars.

My question is therefore:

How do I get a list of files for a given project, so that I can just copy files it depends on, but without declaring the same dependencies again?

In other words…

ProjectA (Gradle build) depends on someJar, version m.n

ProjectB (Gradle script calling ant.importBuild) depends on ProjectA (used to copy all jar files from ProjectA/jars)

I can of course declare ProjectB to depend on ProjectA using settings.gradle, but how do I get the jar files it depends on?

Help is much appreciated here. Thank you in advance!

// Povl


(Gary Hale) #2

If ProjectA and ProjectB are part of the same multi-project build, you can directly access ProjectA from ProjectB:

project(':ProjectA').configurations.compile.each { ... }

A more gradle-ish way, however would be to add ProjectA to some configuration of ProjectB and let that do the copying for you. For instance:

dependencies {
  runtime project(':ProjectA')
}
  task runtimezip(type: Zip) {
  from configurations.runtime
}

(Povl Kvols) #3

That could actually work, Gary. Thank you for your quick reply!

Also, that was much better than my nasty ugly hacked version:

gradle.taskGraph.whenReady { taskGraph ->
 taskGraph.allTasks.each {
  if(it.toString().indexOf(':ProjectA:compileJava')>0) {
   println it+' <<<<<<<<<<<'
   it.inputs.files.each {
     println '>>>>>>>>
  '+it
   }
  }
   else {
   println it
  }
       }
}