我想使用可选输入(如果存在),如果不存在则继续。
当我运行时gradle -Dorg.gradle.warning.mode=all,我收到了仅指定输入的弃用警告:
任务“:addWorkingCopyInfo”的配置存在问题。通过 TaskInputs 和 TaskOutputs 方法注册无效的输入和输出已被弃用,并计划在 Gradle 5.0 中删除。- 为属性“$1”指定的文件“/Users/robert/test/special-build-tag”不存在。
这是构建脚本中的任务:
task addWorkingCopyInfo(type: Exec) {
inputs.file file("tagFile") // deprecated if the file does not exist
outputs.file file("generated/taginfo")
executable "perl" args "..."
}
Run Code Online (Sandbox Code Playgroud)
我已经看到,@Optional如果我有自定义任务类,我可以添加注释,但这里的情况并非如此。
我最好的解决方案是添加对文件的检查,并且仅将其作为输入(如果存在)。这似乎有效。
task addWorkingCopyInfo(type: Exec) {
def tagFile = new File("tagFile");
if (tagFile.exists()) {
inputs.file tagFile
}
outputs.file file("generated/taginfo")
executable "perl" args "..."
}
Run Code Online (Sandbox Code Playgroud)
有没有更好/更 Gradle 风格的方法来做到这一点?
该方法inputs.files(...)返回TaskInputFilePropertyBuilder提供方法optional()和 的a optional(boolean)。
你试一试:
inputs.files('my-file').optional()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1373 次 |
| 最近记录: |