How to zipTree a task's output files?


(binyan357) #1

Ok I have a couple projects in a multi-project build. Project Foo produces a jar file and in Project Bar, I need to include part of the content from that jar file in another jar file.

task barJar(type: Jar) {

baseName ‘Bar’

from (project(’:Foo’).jar) {

collect { it.isDirectory() ? it : zipTree(it) }

include ‘*.swf’

} }

I get the error

No signature of method: org.gradle.api.internal.file.copy.DefaultCopySpec_Decorated.isDirectory() is applicable for argument types: () values: []

What is the proper way to zipTree this content?


(binyan357) #2

Not saying this is the best way to do it, but I got it working with

task barJar(type: Jar) {
   baseName 'Bar'
   from (zipTree(project(':Foo').jar.outputs.files.singleFile)) {
      include '*.swf'
    }
}

In this specific case I’m only dealing with a single file. However, I would still like to know how to get the collect version working for when a task may have multiple jar outputs.


(binyan357) #3

Actually the previous code didn’t work. I though it was working because I saw the resources in the jar, but they were being picked up by a different from statement. The correct code that uses the collect closure is

task barJar(type: Jar) {
   baseName 'Bar'
   from {
      project(':Foo').jar.outputs.files.files.collect { it.isDirectory() ? it : zipTree(it) }
      include '*.swf'
    }
}