gpt4 book ai didi

gradle - Gradle:根据文件列表从目录中删除文件

转载 作者:行者123 更新时间:2023-12-03 06:25:33 27 4
gpt4 key购买 nike

我目前正在尝试将旧的ant系统迁移到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.

有人知道我在这里缺少什么吗?

最佳答案

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

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

关于gradle - Gradle:根据文件列表从目录中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43888898/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com