Fail a task if another task has not been run

(Eero Aaltonen) #1

We have a primary compilation task that does not have a clean way of checking if it’s up-to-date and a duration of about 40 mins. We have some supplementary tasks that depend on the outputs of the primary compilation task. We do not want to automatically run the first task because of the long duration. I came up with the below approach, but would like to know if there’s a recommended way to handle this kind of case.

task second() {
    doLast {
        if (! file('created_by_primary').exists()) {
            def errMessage = 'My error'
            throw new Exception(errMessage)
        // actual work in 'second' task
second.mustRunAfter first