Two tasks, shared variable

I have two tasks that are executed one after the other, in the first I set a variable that I use in the second:

project.ext.set(“chain”, “empty”)
task swid {
project.ext.set(“chain”, “variant”)
}
task compile{
def propC = project.chain
println propC
}

I always get : empty
as a result

how can I change the variable value in the first task?

The code provided will always return variant, not empty, so you might need to double check what you have provided. The code in both your tasks should be wrapped in a doLast { } to execute with the task rather than at configuration time.

project.ext.set('chain', 'empty')
  
task swid {
    doLast {
        project.ext.set('chain', 'variant')
    }
}

task compile {
    doLast {
        def propC = project.chain
        println propC
    }
}

If your description is accurate, it seems likely that you’re halfway there and swid has doLast { }, but compile does not.

yes I missed the doLast{}, now it’s working perfectly