My plugin has two tasks but I don’t know how to specify a property ONCE and have it change both tasks. The code is:
class Step1 extends DefaultTask {
Map<String,?> env
@TaskAction
public void perform() {
println env
}
}
class Step2 extends DefaultTask {
Map<String,?> env
@TaskAction
public void perform() {
println env
}
}
class MultiStep implements Plugin<Project> {
def env = ["VAR" : "value"]
void apply(Project project) {
Task step1 = project.tasks.create('step1', Step1)
Task step2 = project.tasks.create('step2', Step2)
step1.env = env
step2.dependsOn step1
step2.env = env
}
}
apply plugin: MultiStep
How do I pass a new env
value ONCE to both tasks? Of course, this fails:
MultiStep {
env = ['VAR2':'value2']
}
I want to avoid global variables like ext
. I could create a third task that would only hold common configuration values for both tasks, but I wonder if there is a better way. Thanks.