Kelvin Chung
08/06/2024, 5:31 PMtasks.withType(SomeTask).configureEach {
if (someCondition) {
enabled = false
setDependsOn([])
setFinalizedBy([])
}
}
I have a few questions about this:
• Is the blanking of dependsOn and finalizedBy necessary?
• This doesn't seem like good practice, given that there is no outward guarantee of configure block run order. Is there some kind of alternative if this blanking is deemed necessary?Vampire
08/06/2024, 5:37 PMVampire
08/06/2024, 5:37 PMKelvin Chung
08/06/2024, 5:40 PMproject.findProperty(), which actually says nothing, since some uses assume that the value is finalized at configuration time, and other uses assume that this is setting a mutable extra property.
For now, I'm going to assume the former.Vampire
08/06/2024, 5:48 PMonlyIf { ... } as that is calculated at execution time right before the task would get executed.
Of course at that time it is too late to manipulate dependsOn and finalizedBy.
Whether those are necessary depends a bit on what you want to achieve.
Setting enabled to false, or also using onlyIf { ... } does only disable that task's actions.
Dependency tasks and finalizer tasks will still be run.
So if you really want to suppress those along, you probably have to still empty out those and yes, of course later in the configuration cache there could again get some added.
If a task is "skipped" due to -x / --exclude-task, it is not really skipped, but removed from the task graph, including its dependency tasks and finalizer tasks (if not added due to some other reason).
If you can evaluate the condition at configuration time, it indeed works to manipulate gradle.startParameter.excludedTaskNames.add(...) which then has the same effect as -x and thus does not need the other manipulations.