I have a groovy script aa.groovy:
a = 'foo'
and a second script bb.groovy:
import aa
println "$a"
But it doesn’t work. I’ve tried every combination of
def a = 'foo'
a = 'foo'
@Field a = 'foo'
and …
println "$a"
println "$aa.a"
I can think of, but I can’t get it to work.
You need @Field
, but then you also need an instance from the class. Or you have to declare the field static
.
cat <<EOT > ‘aa.groovy’
import groovy.transform.Field
@Field a = 'dynamic'
@Field static b = 'static'
EOT
cat <<EOT > ‘bb.groovy’
import aa
println(new aa().a)
println(aa.b)
EOT
other option in addition to cfrick’s answer
aa.groovy
class aa {
static b = 'static'
}
bb.groovy
import aa
println "$aa.b"