ExtraPropertiesExtension not visible across tasks

Hi, perhaps I am using them in the wrong way, but I cannot save a value in one task and read it on the next.

here is an example:

task taskA << {
  ext.var1 = 'value1'
}
  task taskB(dependsOn: 'taskA') {
  whatever = ${ext.var1}
}

Error:(160) Execution failed for task ‘taskB’. > cannot get property ‘var1’ on extra properties extension as it does not exist

It seems that it has been saved in task scope instead of global.

If I use project.var1 across tasks it works, but I get the deprecation message about dynamic properties.

What am I doing wrong?

To read the extra property, use ‘taskA.var1’. Note that all tasks get configured before any task gets executed, so you can’t configure ‘taskB’ with a value set during execution of ‘taskA’ (as attempted above).

Hi Peter, thanks for your answer. I am not sure I understood, so I am going to give more context.

What I need to do is: - inject some env variables in Jenkins - have 2 tasks that use those variables to find files/names/locations and publish them in different ways

Since the first part is common, I extracted it as a task on which they both depend (I already worked on them after posting here):

def tasksUsingPublish = [publishA, publishB]
tasksUsingPublish*.dependsOn preparePublishEnv

I wanted the task to save the values in a way that one or both tasks can be called afterwards and access the variables without running the common task again. I think by using << (does it correspont to doLast?) I get the values during execution, not during configuration, and in fact with project.var1 it works. However, doing the same the non-deprecated way with ext.var1 doesn’t find it, meaning that I am probably using the wrong syntax to write or read the variables (just a guess).