Reputation: 513
I have a project that has a folder structure like this
blue/folder1
blue/folder2
red/folder3
red/folder4
and in Gradle I would like to tar up these folders individually so that the output looks like:
build/
tar/
blue/
folder1.tar.gz
folder2.tar.gz
red/
folder3.tar.gz
folder4.tar.gz
Is that possible? How would I do this?
Upvotes: 1
Views: 2830
Reputation: 27958
apply plugin: 'base'
['blue', 'red'].each { colour ->
file(colour).listFiles().each { File folder ->
if (folder.directory) {
Task tarTask = tasks.create(name: "tar${colour.capitalize()}${folder.capitalize()}", type: Tar) {
from folder
destinationDir = "${buildDir}/${colour}"
archiveName = "${folder}.tar"
}
assemble.dependOn tarTask
}
}
}
Upvotes: 2