Gradle:根据Filelist

时间:2017-05-10 09:47:24

标签: gradle build build.gradle

我目前正在尝试将旧的蚂蚁系统迁移到gradle。我很擅长学习并且还在学习,所以也许这只是一件小事,我只是被忽视了。

我有一个名为 delete.list 的文件,其中包含我要删除的文件列表。

到目前为止,这是我的代码:

task deleteLib(type:DeleteFiles) {    
    deleteList = file("${buildDir}/delete.list")
}



 class DeleteFiles extends DefaultTask {

    @SkipWhenEmpty
    @InputFile
    File deleteList

    DeleteFiles()
    {
        description = 'Deletes Libs from Integris zip'
    }

    @TaskAction
    void delete(){
        def lines = deleteList.readLines()
        lines.each {
            delete fileTree(dir: "${project.buildDir}", include: "${it}")
        }
    }
}

delete.list:

lib/java/activation.jar
lib/java/pdfbox*.jar
lib/java/fontbox*.jar
lib/java/xmpbox*.jar
lib/java/jempbox*.jar
lib/java/iText*.jar
lib/java/itext*.jar
lib/java/jakarta-poi.jar
lib/java/commons-net*.jar
lib/java/jfreechart*.jar
lib/java/jcommon*.jar
lib/java/dom4j*.jar
lib/java/xmlbeans*.jar
lib/java/jaxen*.jar
lib/java/avalon-framework*.jar
lib/java/batik-all*.jar

点击谷歌后我找到了这个解决方案,因为我的_delete.list 可能在构建阶段不存在。

我目前的问题是gradle似乎有fileTree方法的问题:

* What went wrong:
Execution failed for task ':deleteLib'.
> Could not find method fileTree() for arguments [{dir=C:\entwicklung\Testumgebung\testProjectGradle\build, include=lib/java/activation.jar}] on task ':deleteLib' of type DeleteFiles.

有人知道我在这里失踪的是什么吗?

1 个答案:

答案 0 :(得分:-1)

由于两个方法都在Project上定义,并且groovy查找task中定义的方法,因此需要显式调用project实例上的方法:

project.with {
   delete fileTree(dir: "${project.buildDir}", include: "${it}")
}