Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the matter with IntelliJ's Groovy console?

When I try to use the groovy console it just doesn't seem to recognize and understand the previous stements entered. And code completion does not work either. Below is a VERY simple example that fails. Creating a list and trying to add an integer to that list. The created list isn't found!

> def list = []
[]
> list.add(10)
groovy.lang.MissingPropertyException: No such property: list for class: ideaGroovyConsole
Possible solutions: class
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at ideaGroovyConsole.run(ideaGroovyConsole.groovy:1)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)
at groovy.lang.GroovyShell.run(GroovyShell.java:481)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:231)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at console.run(console.txt:25)
at groovy.ui.GroovyMain.processReader(GroovyMain.java:563)
at groovy.ui.GroovyMain.processFiles(GroovyMain.java:473)
at groovy.ui.GroovyMain.run(GroovyMain.java:373)
at groovy.ui.GroovyMain.process(GroovyMain.java:361)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
at groovy.ui.GroovyMain.main(GroovyMain.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121
like image 563
Paddan Avatar asked Oct 21 '22 18:10

Paddan


1 Answers

Don't def and you should be good.

> list = []
[]
> list.add(10)

The behaviour is more like groovyShell than groovyConsole.

Perhaps this link explains why: http://groovy-lang.org/groovysh.html#GroovyShell-Variables

like image 114
kdabir Avatar answered Oct 24 '22 00:10

kdabir