Fail Gradle Copy task if source directory not exist

前端 未结 2 876
半阙折子戏
半阙折子戏 2021-01-13 03:57

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 p

相关标签:
2条回答
  • 2021-01-13 04:25

    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.

    0 讨论(0)
  • 2021-01-13 04:46

    This worked for me:

    task copySpecificPlatform(type: Copy) {
        from 'source/directory'
        into 'target/directory'
        if(inputs.sourceFiles.empty) throw new StopExecutionException("No files found")
    }
    
    0 讨论(0)
提交回复
热议问题