Gradle - Delete files with certain extension

Use the Gradle Delete task.

task deleteFiles(type: Delete) {
    delete fileTree('dir/foo') {
        include '**/*.ext'

You may customize default clean task to include other directories and files for deletion like:

  delete 'buildDir', 'generated'

If you want use glob, you may use fileTree for example, or any other convenient methods to list files:

  delete 'build', 'target', fileTree(dockerBuildDir) { include '**/*.rpm' }

There are several ways to delete files with certain extension.In general,you must select some files;then filter some of them and finally delete reminding file.For example try this :

def tree = fileTree('${SOME_DIR}') 
tree.include '**/*.${SOME_EXT}'
tree.each { it.delete() }