Gradle删除文件集

时间:2017-09-18 14:09:41

标签: gradle

我正在尝试删除一组文件,因为我在很多examples

task deleteApkFiles(type: Delete) << {
  println("-------------------------------------")
  println("---------------DELETE---------------")
  println("-------------------------------------")
  def files = fileTree(dir: '.', include: '**/*.apk').files
  delete fileTree(dir: '.', include: '**/*.apk')
  println(files)

}

打印仅向我显示我想要删除的文件

[app-minAPI16-prod-release.apk, app-minAPI16-prod-release.apk, app-minAPI16-beta-debug.apk]

但是delete不会删除它们

2 个答案:

答案 0 :(得分:1)

只需删除<<

即可

它会起作用。我不知道为什么=)

task deleteApkFiles(type: Delete)  {
  println("-------------------------------------")
  println("---------------DELETE---------------")
  println("-------------------------------------")
  delete fileTree(dir: '.', include: '**/*.apk')
}

答案 1 :(得分:0)

设法删除foreach循环中的文件

def files = fileTree(dir: '.', include: '**/*.apk').files
files.each {File f -> delete f}