Fullmenu null

 

02 August 2017

Groovy is a dynamic programming language for the java virtual machine (Java Virtual Machine). This means that the generated code can be executed by the Java Runtime and therefore it is required to have Java 6+ installed (recommended Java 8 and very soon Java 9)

Binaries using

You just have to download the binaries from the official page, unzip it in a directory and adjust the environment variables GROOVY_HOME and PATH

Windows

There is an NSIS-based Windows installer that will allow us to install and uninstall Groovy on our machine

Maven (and similar)

It is also possible to embed Groovy in our projects using artifacts:

<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.4.12</version>

SdkMan

To incorporate the groovy tool we recommend installing SdkMan (http://sdkman.io/). This software is very practical both to install and to handle the different versions of the installed tools.

With the sdkman in our system run:

sdk install groovy

Testing

Once the installation command is finished, we will verify that we have the groovy installed.

groovy -version

GroovyConsole

We are ready to launch our first groovy console

groovyConsole

In a few seconds our groovy console will open where we can start working with the first scripts

groovy console

To perform a simple test we can execute our first "Hello World":

HolaMundo.groovy
println "Hola mundo"

Through the Groovy Console menu we can execute the script and visualize the result in the lower panel.

Console

The groovy console is very useful when we are developing our script because it allows us to execute it, correct it and re-execute it in the same place. However, we can also use our text editor (is not Word) such as Notepad, Notepad ++, gedit, vi, emacs, etc. and execute it from console (or embedded in a bash for example)

groovy HolaMundo.groovy

Groovy Web Console

Finally, you can also try using the online console https://groovyconsole.appspot.com/ which will allow you to execute some simple scripts (and shar it)


Script
println "Hola mundo"