Questions tagged [groovyshell]

The term groovyshell refers to both: 1. A command line interactive groovy shell, usually invoked as "groovysh" 2. One of the primary classes (groovy.lang.GroovyShell) in the Groovy language API for dynamically compiling and invoking groovy scripts from their raw source state.

The term groovyshell refers to both:

  1. A command line interactive groovy shell, usually invoked as "groovysh"
  2. One of the primary classes groovy.lang.GroovyShell) in the Groovy language API for dynamically compiling and invoking groovy scripts from their raw source state.

Groovysh

A command line groovy interpreter, well documented in the official documentation.

GroovyShell (the class)

groovy.lang.GroovyShell is one of the core classes of the Groovy runtime. It provides support for interpreting, evaluating and compiling groovy scripts in their raw source state. The base support for source read targets are:

  1. Java Files
  2. Java Input Streams
  3. Java Readers
  4. Java Strings
  5. Groovy GroovyCodeSources (A special source construct that isolates the contained source and generated byte code)
247 questions
195
votes
9 answers

Groovy Shell warning "Could not open/create prefs root node ..."

I tried to open the Groovy Shell (groovysh) on Windows 8 and got the following output: java.util.prefs.WindowsPreferences WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...)…
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
51
votes
2 answers

Strange variable scoping behavior in Jenkinsfile

When I run the below Jenkins pipeline script: def some_var = "some value" def pr() { def another_var = "another " + some_var echo "${another_var}" } pipeline { agent any stages { stage ("Run") { steps { …
haridsv
  • 9,065
  • 4
  • 62
  • 65
36
votes
5 answers

get current date and time in groovy?

What is the code to get the current date and time in groovy? I've looked around and can't find an easy way to do this. Essentially I'm looking for linux equivalent of date I have : import java.text.SimpleDateFormat def call(){ def date = new…
Scooby
  • 3,371
  • 8
  • 44
  • 84
15
votes
1 answer

Avoiding sharing Java meta classes across different Groovy scripts

My situation I call multiple Groovy scripts from Java, they both contain long-lived Groovy objects. I would like my Groovy scripts to make some changes to a Java meta-class for a Java class (that have about 100 instances). However, the scripts…
Simon Forsberg
  • 13,086
  • 10
  • 64
  • 108
14
votes
1 answer

How catch curl response into variable in Jenkinsfile

I want to curl an URL and capture the response into a variable. when I curl a command and echo its output I get the correct response as below sh 'output=`curl https://some-host/some-service/getApi?apikey=someKey`;echo $output;' I want to catch the…
Anand Deshmukh
  • 1,086
  • 2
  • 17
  • 35
10
votes
1 answer

How to list all binding variables with GroovyShell

I'm very new to Groovy. How can I list all variables I passed to Binding constructor ? Considering I have following : @Test public void test() { List outputNames = Arrays.asList("returnValue", "ce"); String script = getScript(); …
lisak
  • 21,611
  • 40
  • 152
  • 243
10
votes
3 answers

MissingPropertyException in groovysh

I run groovysh, and type the following code: groovy:000> String s = "Hello" ===> Hello groovy:000> s ERROR groovy.lang.MissingPropertyException: No such property: s for class: groovysh_evaluate at groovysh_evaluate.run (groovysh_evaluate:2) …
Freewind
  • 193,756
  • 157
  • 432
  • 708
10
votes
3 answers

difference between int and Integer type in groovy

I have just started learning groovy and I am reading "Groovy in Action". In this book I came across a statement that it doesn’t matter whether you declare or cast a variable to be of type int or Integer.Groovy uses the reference type ( Integer )…
Abhinandan Satpute
  • 2,558
  • 6
  • 25
  • 43
9
votes
3 answers

Using GroovyShell as "expression evaluator/engine" (or: How to reuse GroovyShell)

I'm using GroovyShell as an "expression evaluator/engine" inside my program. It accepts two inputs: (a) one or more init scripts (b) user-defined script. Both are then concatenated at runtime as big chunk of script (text) and feed to the…
wiradikusuma
  • 1,930
  • 4
  • 28
  • 44
7
votes
1 answer

How to add multiple jars to the classpath of groovyConole/groovysh?

This feels ridiculous that I have to ask this, but I can't seem to add multiple jar files to the classpath for groovyConsole and groovysh. How do I add multiple jar files to the classpath? Here is what I've tried: groovyConsole -cp…
chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
6
votes
1 answer

groovysh cannot find method

I load the following script into groovysh: def a() { println "a()" } def b() { println "b()" a() } by using :load 'test.groovy' and call method b(): b() I get: groovy:000> b() b() No signature of method: groovysh_evaluate.a() is…
Matvey Masov
  • 111
  • 5
6
votes
2 answers

Java vs. Groovy inner / outer class discrepancy

Java: public final class Outer { public static void main(String[] args) { Inner.inner(); } private static final class Inner { private static void inner() { System.out.println("inner"); outer(); } } …
levant pied
  • 3,886
  • 5
  • 37
  • 56
6
votes
3 answers

Grails shell not seeing domain objects

I'm a grails newbie (and a groovy newbie), and I'm working through some grails tutorials. As a new user, the grails shell is a really useful little tool for me, but I can't figure out how to make it see my classes and objects. Here's what I'm…
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
6
votes
1 answer

Which maven dependency to include for evaluating groovy scripts in java application

I've added the ability to parse and evaluate groovy scripts inside my java application using GroovyShell. Which maven artifact is the bare minimum to include in my build? I know that the groovy-all will definitely contain everything I need, but I'm…
Billybong
  • 697
  • 5
  • 18
6
votes
4 answers

Running a script from Groovy

In order to get my setup a bit closer to "one click deployment", I would like to use groovy scripts to start/stop other processes controlled by bat scripts, running in different parts of the filesystem and even on different machines. How to execute…
raoulsson
  • 14,978
  • 11
  • 44
  • 68
1
2 3
16 17