Groovy console can’t “remember” any variables – always says “unknown property”

This is standard behavior in the Groovy shell, not peculiar to the Grails shell. You probably don’t want to def the variable. See the following:

~ $ groovysh
Groovy Shell (2.3.4, JVM: 1.7.0_45)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> def x = 42
===> 42
groovy:000> x
Unknown property: x
groovy:000> y = 2112
===> 2112
groovy:000> y
===> 2112
groovy:000>

From http://beta.groovy-lang.org/groovysh.html

1.3.4. Variables

Shell variables are all untyped (ie. no def or other type information).

This will set a shell variable:

foo = "bar"

But, this will evaluate a local variable and will not be saved to the shell’s environment:

def foo = "bar"

You can change this behaviour by enabling interpreterMode

groovy:000> := interpreterMode
groovy:000> def x = 42
===> 42
groovy:000> x
===> 42
groovy:000>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)