Reputation: 13395
I want to zip the content of package folders.
How to do it in a gradle
task?
I am trying to do like this
task publishAll << {
new File('src/main/resources/com/domain/application/').eachDir() {
dir -> processFolder(dir)
}
}
def processFolder(dir) {
println "prepare folder: " + dir
And it seems to return first-level subfolders fine.
But how to zip that dir
folder?
Upvotes: 1
Views: 1006
Reputation: 28096
You can make a custom task with the Zip
type and use FileTree
to include all subfolder with it's contetnt into the zip-archive, like:
task publishAll(type: Zip){
from fileTree(dir: 'src/main/resources/com/domain/application/')
}
If you want additionally print the file names, you can modify it to:
from fileTree(dir: 'src/main/resources/com/domain/application/').each {println it.name}
Update: to archive every folder in separate zip-file, you can use your solution to traverse over directories and add the ant.zip
task, to pack them, like:
task publishAll << {
new File('src/main/resources/com/domain/application/').eachDir {
ant.zip(destfile: it.name+'.zip', basedir: it.path){
}
}
}
Upvotes: 1