The next piece of Groovy code works in Grails (thanks @Will P) for your answer:
String string2code = "variable = 'hello'; return variable.toUpperCase()";
def result = new GroovyShell().evaluate string2code
assert result == "HELLO"
Unfortunately, if we introduce the magic querying of Grails, it fails:
String string2code = "return DomainClassExample.findByName('hello')";
// String string2code = "DomainClassExample.where { name == 'hello' }"
def queryResult = new GroovyShell().evaluate string2code
This is the error:
Class
groovy.lang.MissingPropertyException
Message
No such property: DomainClassExample for class: Script1
Is it possible? How?