Can someone please help me to find a way to force a Gradle task to re-run on each call, Gradle is executing it only one. Sample build.gradle to replicate the scenario.
Are you expecting the finalizedByTask to run multiple times? Each task will execute either 0 or 1 times per Gradle invocation. Perhaps you need a finalizer for each task? Hard to know without more context
Thanks, @Lance for the prompt response, yes I have to run “finalizedByTask” multiple times, after the completion of each task -deployProduct & functionalTests. So I have to run it two times but it is executing only once.
task restartServer{
//Do necessory stuff
}
task deployProduct {
//copy jar in auxPath of server, this will be picked up after server restart
finalizedBy restartServer
}
task functionalTests{
dependsOn deployProduct
//Run tests
//Restart server to clean cache and kills running jobs
finalizedBy restartServer
}
That’s not how gradle works. As I said, a task will never execute twice in a single Gradle invocation. It’s not a method call. I’m guessing you’ll need multiple instances of the same task type, each with slightly different configuration (ie a different directory for each)
@Lance if Gradle api is not designed to run a task twice per gradle invocation, can you please hint me into a good direction on this question? Force rerun a task by another task