如何扩展gradle的clean任务来删除文件? [英] How do I extend gradle's clean task to delete a file?

查看:467
本文介绍了如何扩展gradle的clean任务来删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已将以下内容添加到我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆