I think global properties should be avoided and gradle offers you a nice way to do so by adding properties to a task:
task task1 {
doLast {
task1.ext.variable = "some value"
}
}
task task2 {
dependsOn task1
doLast {
println(task1.variable)
}
}