Gradle任务行总是得到执行

Gradle任务行总是得到执行,gradle,build.gradle,Gradle,Build.gradle,我有以下Gradle任务: task deploy(type: Exec) { doFirst { println 'Performing deployment' } final Map properties = project.getProperties() if (!properties['tag']) { throw new StopExecutionException("Need to pass a tag p

我有以下Gradle任务:

task deploy(type: Exec) {
    doFirst {
        println 'Performing deployment'
    }

    final Map properties = project.getProperties()

    if (!properties['tag']) {
        throw new StopExecutionException("Need to pass a tag parameter")
    }

    commandLine "command", tag
}
如果我运行另一个任务,我会得到一个错误,因为属性['tag']未定义,我猜是因为Gradle正在执行任务中除命令行以外的所有内容。有没有更好的方法来实现这一点,或者有什么方法可以阻止Gradle即使在我运行另一个任务时也执行部分任务

使用Gradle 6.6.1时,我使用以下模式:

//Groovy DSL
任务。注册(“exec1”,Exec){
def tag=project.findProperty(“标记”)?:“”
命令行“echo”,标记
首先{
如果(!标记){
抛出新的GradleException(“需要传递标记参数”)
}
}
}
它添加
标记
属性(如果存在)

如果它不存在,它会添加一个空字符串,但会在实际运行之前进行检查

如果Exec任务接受providers作为参数,那么您就可以给它
providers.gradleProperty(“tag”)
,但不幸的是,它没有