We can use the Apache Groovy programming language for scripting our software builds and automating some otherwise cumbersome tasks. Groovy is a Java virtual machine (JVM) language, which is similar to Java but less verbose. This makes it excellent for scripting.
Make Sure You Have Java JDK Installed
You’ll need to make sure you have a working Java environment setup. You need to check if you have the JDK installed. Open a command prompt and type "java -version." If it shows the current version of the JDK, you are set for installing Groovy.
Just to make sure, it is best you have a recent version 1.7 or upwards. If you don't have the JDK, or are running an older version, you'll have to install it. More on installing the JDK here.
Do You Already Have Groovy?
Next we’ll check if you have Groovy already installed. If you have it installed, you’ll also be able to see the version and, if necessary, download a more recent version.
Let’s open a command prompt. I use (shortcut: windows key + R) to open the run box where I type cmd and press ok.
Next you can enter the following in the command prompt: groovy -v. Which, if you haven’t installed it, results in:
‘groovy’ is not recognized as an internal or external command,
operable program or batch file.
Downloading the Groovy Language
So you don’t have Groovy installed. We’ll download groovy at http://www.groovy-lang.org/, where the download section can be found in the top menu. When you are in the download section, you can download the binary of the most recent distribution.
When the download is finished, you can extract the zip to a location where you want groovy installed. I have a section on my hard drive for development related tools and packages. I create a folder there named "Groovy" and export this distribution to that folder.
Adding Groovy to Environment Variables
You can find your environment variables section when you open the “control panel” -> “system” -> “advanced system settings”.
When you open environment variables, you can choose to add a new variable. For variable name, we enter GROOVY_HOME. Next we enter the variable value. This is the location of your groovy installation. In my case, that is C:\Development\groovy\groovy-2.4.8. Then we just press ok and should see the newly added variable.
When we’ve added the variable, we should edit the “path” variable. We need to add our groovy variable to the path and the \bin to it. %GROOVY_HOME%\bin and save the path.
When all of the above is entered successfully, we can try our groovy -v command again in the prompt. We should see our Groovy version and JVM installation.
Groovy for Java Developers
This content is accurate and true to the best of the author’s knowledge and is not meant to substitute for formal and individualized advice from a qualified professional.
© 2017 Sam Shepards