0

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.

Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • Didn't the answers at your other question help? http://stackoverflow.com/questions/35596011/could-not-find-property-uninstalldebug-on-project – RaGe Feb 25 '16 at 11:10
  • @RaGe No. I tried `whenReady` which results in *Could not find property 'spoonFreeAndroidDebugTest' on project ':app'.* Code snippet to follow: `gradle.taskGraph.whenReady {taskGraph -> taskGraph. if (taskGraph.hasTask(spoonFreeDebugAndroidTest)) { spoonFreeAndroidDebugTest.finalizedBy "ciIntegrationTests" } }` – Rajkiran Feb 25 '16 at 11:44
  • @RaGe I have updated the question. – Rajkiran Feb 25 '16 at 13:08
  • I missed the "even if task fails" part of your question earlier. You can make gradle continue on failure if you run with the `--continue` flag. See if that helps. Be mindful that that flag will continue past errors in other parts of your buildscript as well. – RaGe Feb 25 '16 at 13:13

1 Answers1

0

Wrap your task string with tasks["taskName"]

tasks["spoonDeltaAndroidDebugTest"].finalizedBy tasks["ciIntegrationTests"]

Reference: More About Tasks