如何扩展gradle的clean任务来删除文件? [英] How do I extend gradle's clean task to delete a file?
问题描述
到目前为止,我已将以下内容添加到我的build.gradle中:
apply plugin:'base'
清洁<< {
delete'$ {rootDir} / api-library / auto-generated-classes /'
println'$ {rootDir} / api-library / auto-generated-classes /'
}
然而,不仅我的文件没有被删除,而且print语句显示 $ {rootDir}
未被转换为我的项目的根目录。为什么不行,我缺少什么概念?
您只需要使用双引号。另外,如果您打算在执行期间执行删除操作,请删除<<
并使用 doFirst
。像这样:
clean.doFirst {
delete$ {rootDir} / api-library / auto-generated -class /
println$ {rootDir} / api-library / auto-generated-classes /
}
Gradle构建脚本使用Groovy DSL编写。在Groovy中,您需要使用双引号进行字符串插值(当您使用 $ {}
作为占位符时)。查看此处。
So far i've added the following to my build.gradle
apply plugin: 'base'
clean << {
delete '${rootDir}/api-library/auto-generated-classes/'
println '${rootDir}/api-library/auto-generated-classes/'
}
However not only is my file not deleted, but the print statement shows that ${rootDir}
is not being converted to the root directory of my project. Why won't this work, what concepts am I missing?
You just need to use double quotes. Also, drop the <<
and use doFirst
instead if you are planning to do the deletion during execution. Something like this:
clean.doFirst {
delete "${rootDir}/api-library/auto-generated-classes/"
println "${rootDir}/api-library/auto-generated-classes/"
}
Gradle build scripts are written in Groovy DSL. In Groovy you need to use double quotes for string interpolation (when you are using ${}
as placeholders). Take a look at here.
这篇关于如何扩展gradle的clean任务来删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!