Hey! I've got a project with a bunch of tasks. Dur...
# community-support
a
Hey! I've got a project with a bunch of tasks. During execution time, I'd like to, in a task, to prevent all other tasks of the project from executing. I tried setting
onlyIf {false}
on the tasks, or to add doFirst{} and throw a StopExecutionException, but they all fail. is there a way to do what I want?
I cannot make the decision in configuration time because the decision is based on a network call - doing it it configuration time doesn't seem desired.
j
you probably need to make all the other tasks depend on that task
a
I see, but how to express the skipping/
I currently think setting task,onlyIf {false} on the tasks is the right approach, as it seemes to be evaluated in the execution time.
okay this works, perfect. thank for mental support 😄
j
if a prerequisite task fails, tasks that depend on it are skipped as the build fails before they start ... an important point here is that the other tasks won't start until the task they depend on is completed, I'm not sure this is guaranteed with your approach
a
if task A depends on task B and I skip B, does it prevent A from running?
v
No
Also,
onlyIf { false }
is not too helpful, you can as well just set
enabled = false
.
And configuring one task from the execution phase of another task is highly discouraged bad practice and if you ever want to use configuration cache, latest then it will not work.
You should probably do your check in the implementation of a shared build service and then query that build service for the result in
onlyIf { ... }
or something like that.
Why is what I just said, isn't it? 🙂
e
ah I didn't scroll to the bottom of the thread, I see it now
👌 1