You can add properties to tasks using the ext property in the task:
task3.doFirst {
ext.aproperty = "Property, yo."
}
Then once you're in task3 you can reference ext.aproperty.
You can set properties before tasks are run based on what tasks are specified on the command line:
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release)) {
version = '1.0'
} else {
version = '1.0-SNAPSHOT'
}
}
Providing you have a 'release' task, and you call it on the command line, the build script will have '1.0' as its version property, otherwise it will have '1.0-SNAPSHOT'.