如何确保跳​​过doLast甚至任务

时间:2016-05-28 03:52:53

标签: java gradle groovy

我有以下代码:

jar.doLast {
    def isFailed = jar.state.failure
    def proc
    if (isFailed) {
        proc = ['notify-send', "-u", "critical", "Build ${project.name} failed"].execute()
    } else {
        proc = ['notify-send', "Build ${project.name} finish"].execute()
    }
    proc.waitForProcessOutput(System.out, System.err);
}

当我第一次运行gradle --daemon jar时,它发送通知,当我再次运行它时,jar.doLast没有运行,我认为这是因为,gradle自动跳过jar,因为src与旧src相同,所以如何确保jar.doLast在第二种情况下运行?

1 个答案:

答案 0 :(得分:0)

感谢@Aarjav,我使用以下代码:

jar {
    outputs.upToDateWhen { false }
}

jar.doLast {
    def isFailed = jar.state.failure
    def proc
    if (isFailed) {
        proc = ['notify-send', "-u", "critical", "Build ${project.name} failed"].execute()
    } else {
        proc = ['notify-send', "Build ${project.name} finish"].execute()
    }
    proc.waitForProcessOutput(System.out, System.err);
}

它会强制运行jar,并且jar任务不会浪费太多(与compileJava相比),它不会影响构建时间