I’m relatively new to gradle.
In order to create an automated deployment script on a cluster, I have created a bunch of Custom tasks that will depend on each other. For example:
class StartSchedulerTask extends SchedulerTask {
@TaskAction
void start() {
dependsOn env.nodes.name.collect {"startTomcat_$it"}
println "Starting quartz on node: ${node}"
}
}
in build.gradle, i have dynamically created the tasks:
project.extensions.environment.nodes.each { TomcatNode n ->
String name = n.name
task "nodeInit_$name"(type: DeployToNodeInitTask) {
node(n)
}
task "stopWorker_$name"(type: StopWorkerTask) {
node(n)
}
task "stopTomcat_$name"(type: StopTomcatTask){
node(n)
}
task "updateAppConfigs_$name"(type: UpdateAppConfigsTask){
node(n)
apps(V3Application.ALL_APPS)
buildName('develop')
}
task "deployWars_$name"(type: DeployWarsTask){
node(n)
apps(V3Application.ALL_APPS)
buildName('develop')
}
task "startTomcat_$name"(type: StartTomcatTask){
node(n)
}
task "startWorker_$name"(type: StartWorkerTask){
node(n)
}
task "terminateNode_$name"(type: DeployToNodeTerminationTask){
node(n)
}
}
task stopScheduler(type: StopSchedulerTask) {
environment(environment)
}
task startScheduler(type: StartSchedulerTask) {
environment(environment)
}
The default task is configured to be startScheduler, which is the last step of the deployment process, the idea being that the task graph, once it is built, will take care of the correct execution order of my tasks.
However, when I print out the task graph, the only task listed is startScheduler. Am I missing something?
Thanks to the remark of Peter Niederwieser and Jeffrey, I was able to come up with the full solution I want. I did not mark Peter’s as the answer, because the full answer is below, but it was a necessary hint to the right solution:
I Created an interface DependencyAware:
Every task that knows how to declare its dependencies, implements this interface. For example:
In my build script:
That’s it!
Thanks for the pointers Peter and Jeffrey
UPDATE 1
The internal dependencies between the different deployment steps, are in the tasks themselves, for example:
The declaration of the topology is as follows: