如果源目录不存在,则 Gradle Copy 任务失败 [英] Fail Gradle Copy task if source directory not exist

查看:20
本文介绍了如果源目录不存在,则 Gradle Copy 任务失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Gradle 创建构建脚本.我想保护脚本免受错误属性的影响,脚本中的任务之一是简单的复制任务,我注意到当我将不存在的目录作为 from 参数时,任务继续使用 Skipping任务 ':copySpecificPlatform' 因为它没有源文件.

有没有办法在这种情况下导致复制任务失败?

解决方案

你可以试试:

task cp(type: Copy) {从空"进入目标"输入.sourceFiles.stopExecutionIfEmpty()}

每个任务都有它的TaskInputs 哪些源文件是 FileCollection 具有特殊的 方法.p>

I'm using Gradle to create a build script. I want to protect the script from wrong properties, one of the tasks in the script is simple Copy task and I notice that when I put non-exist directory as from parameter the task continue with Skipping task ':copySpecificPlatform' as it has no source files.

Is there a way to cause the copy task to fail in this case?

解决方案

You can try:

task cp(type: Copy) {
    from 'empty'
    into 'target'
    inputs.sourceFiles.stopExecutionIfEmpty()
}

Every Task has its TaskInputs which source files are a FileCollection that has special method which configures the desired behavior.

这篇关于如果源目录不存在,则 Gradle Copy 任务失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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