Search code examples
javazipgradle

Gradle Zip task to do multiple sub-trees?


We're trying to build up a minorly complicated Zip file in Gradle from multiple filesystem source trees, but no matter how many into specifications we give, it all puts them in the same one. Is this possible to do in Gradle?

build/libs/foo.jar --> foo.jar
bar/*              --> bar/*

We're getting this instead:

build/libs/foo.jar --> bar/foo.jar
bar/*              --> bar/*

Using this:

task installZip(type: Zip, dependsOn: jar) {
    from('build/libs/foo.jar').into('.')
    from('bar').into('bar')
}

Any help would be appreciated.

EDIT: Gradle 1.0-milestone-3


Solution

  • Try this:

    task zip(type: Zip) {
        from jar.outputs.files
        from('bar/') {
            into('bar')
        }
    }
    

    First... the jar should be in the root / of the zip (which seems to be what you want). Second, by specifying the from jar.outputs.files, there is an implicit dependsOn on the jar task, so this shows another way of accomplishing what you want. Except with this approach if the jar name changes over time it doesn't matter. Let me know if you need additional help.