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

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

问题描述

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

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()
}

每个任务 TaskInputs 哪些源文件是 FileCollection = http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.html#stopExecutionIfEmpty() 相对=nofollow >方法,它配置所需的行为。

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天全站免登陆