UPDATE
I could get hold of the task at the runtime. But I am not able to finalize another task. The code I used for is:
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(spoonFreeDebugAndroidTest)) {
for(Task task : project.gradle.taskGraph.allTasks.iterator())
{
if(task.name.startsWith("spoonFreeDebugAndroidTest")) {
println "spoonFreeDebugAndroidTest task found"
ciIntegrationTests.mustRunAfter task.name
task.finalizedBy "ciIntegrationTests"
}
}
}
}
But, still the task "ciIntegrationTests" does not get executed when "spoonFreeDebugAndroidTest" fails. (The println line gets printed though.)
ORIGINAL QUESTION
I have a spoon task which is built at the runtime (when the task graph is generated) depending on my app flavours. e.g. A task "spoonFreeAndroidDebugTest" is generated at run time and is not accessible to me in build.gradle.
I want to add a dependancy on this task so that this task executes even if some other task fails. I tried these approaches:
spoon.finalizedBy "ciIntegrationTests"
which gives me this error
Could not find method finalizedBy() for arguments [ciIntegrationTests] on com.stanfy.spoon.gradle.SpoonExtension_Decorated@147456b6.
and
spoonFreeAndroidDebugTest.finalizedBy "ciIntegrationTests"
which gives me an error
Could not find property 'spoonDeltaAndroidDebugTest'
and
"spoonDeltaAndroidDebugTest".finalizedBy "ciIntegrationTests"
which results in
No signature of method: java.lang.String.finalizedBy() is applicable for argument types: (java.lang.String) values: [ciIntegrationTests]
Is there a way we can access a task in build.gradle which is generated at runtime.
Wrap your task string with tasks["taskName"]
tasks["spoonDeltaAndroidDebugTest"].finalizedBy tasks["ciIntegrationTests"]
Reference: More About Tasks