我有以下代码:
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在第二种情况下运行?
答案 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相比),它不会影响构建时间