Is it possible to have a task mark itself as `up-t...
# community-support
t
Is it possible to have a task mark itself as
up-to-date
or
skipped
from within the main
@TaskAction
function? use-case: task that will use an exec of git to grab time information about a file then make 2 or 3 api calls to determine the state of the file on a 3rd party remote to decide if it should do the actual task action of uploading for processing. I've got dozens of this task type in a single invocation and I want to be able to filter my buildscan timeline/logging quick and easy.
I suppose I could probably lift the api/git to another load task then use it as an input. then look at the value via only if predicate
v
Yes,
onlyIf
is execution time and I/O should thus be fine. Within a task action you cannot mark a task as up-to-date or skipped, because it is already running, so it can neither be up-to-date nor skipped, because it is already running. But you can just return from the task action, not doing the work if
onlyIf
for example is not an option.
👌 1
t
You can set
didWork
from the task action though: https://docs.gradle.org/current/dsl/org.gradle.api.Task.html#org.gradle.api.Task:didWork (no idea how it will reflect in the task status, possibly up-to-date)
til 1
t
didWork = false
seems to mark it as up to date so long as there was no other action after you set it to false. IE: this will produce an
UP-TO-DATE
Copy code
tasks.register("behaviorCheck") {
    doFirst {
        println("doing first")
        didWork = false
    }
}
where as this will produce a
SUCCESS
Copy code
tasks.register("behaviorCheck") {
    doFirst {
        println("doing first")
        didWork = false
    }
    doLast {
        println("doing last")
    }
}
but that lets me do exactly what I need without having to split it out to another task
TY