Reputation: 1937
I need to create a gradle task to create a zip where I need to include all the json files that contain text "type":"customer" how can i include the check for containing text ? is there a way I can do it:
task createZip(type: Zip) {
archiveName = "customer.zip"
destinationDir = file(testDir)
from(files(customer))
}
Upvotes: 1
Views: 312
Reputation: 12126
You could use a FileTree together with Gradle/Groovy filtering capabilities:
Let's say you have your source Customer JSON files under src/customers
: you can define a Task like that:
task createZip(type: Zip) {
archiveName = "customer.zip"
destinationDir = buildDir
from fileTree('src/customers').filter { f -> f.text.contains('"type": "customer"')}
}
Note that this uses Groovy's File.getText() method to read the whole file content into memory to match the "type": "customer"
expression. Be careful with performances if you have plenty or huge files to filter.
Upvotes: 1