失败 Gradle 如果源目录不存在则复制任务
Fail Gradle Copy task if source directory not exist
我正在使用 Gradle 创建构建脚本。我想保护脚本免受错误属性的影响,脚本中的任务之一是简单的复制任务,我注意到当我将不存在的目录作为 from
参数时,任务继续 Skipping task ':copySpecificPlatform' as it has no source files.
在这种情况下,是否有办法导致复制任务失败?
你可以试试:
task cp(type: Copy) {
from 'empty'
into 'target'
inputs.sourceFiles.stopExecutionIfEmpty()
}
配置所需行为的每个 Task has its TaskInputs which source files are a FileCollection that has special method。
这对我有用:
task copySpecificPlatform(type: Copy) {
from 'source/directory'
into 'target/directory'
if(inputs.sourceFiles.empty) throw new StopExecutionException("No files found")
}
我正在使用 Gradle 创建构建脚本。我想保护脚本免受错误属性的影响,脚本中的任务之一是简单的复制任务,我注意到当我将不存在的目录作为 from
参数时,任务继续 Skipping task ':copySpecificPlatform' as it has no source files.
在这种情况下,是否有办法导致复制任务失败?
你可以试试:
task cp(type: Copy) {
from 'empty'
into 'target'
inputs.sourceFiles.stopExecutionIfEmpty()
}
配置所需行为的每个 Task has its TaskInputs which source files are a FileCollection that has special method。
这对我有用:
task copySpecificPlatform(type: Copy) {
from 'source/directory'
into 'target/directory'
if(inputs.sourceFiles.empty) throw new StopExecutionException("No files found")
}