The issue is that the environment variables are read into a static variable. The classloaders (and therefore the static state of any loaded classes) are retained between build invocations. This is the intended behavior since Gradle 2.4 and would have been the behavior for some things before that.
The example provided in the OP is a little too simple to know exactly how you’re using the environment variables, but I would suggest either using extra properties that are initialized to the environment variable’s values or making the Globals
class an extra property.
Here’s the second option:
class Globals {
String root = System.getenv( 'ROOT_FOLDER' ).toString().replace( "\\","/" )
String gid = System.getenv( 'GID' )
String buildResultsGid = "${root}/build/Results/${gid}/demo"
}
ext {
globals = new Globals()
}
// reference it like:
println "value of ROOT_FOLDER = " + globals.root