Groovy is a dynamic language for the Java platform. It runs on the JVM, uses Java’s libraries directly, and accepts almost all Java syntax — but adds shortcuts that make everyday code dramatically shorter. That’s why it’s everywhere scripts are needed in the Java world: Gradle build files, Jenkins pipelines, Spock tests, and Boomi Data Process scripts (see the Boomi Groovy guides on the blog).
If you know some Java, you already know a lot of Groovy. If you don’t, Groovy is a friendly first language: less ceremony, instant results.
Install Groovy
Groovy needs a JDK (see Getting started with Java). Then the easiest route is SDKMAN (macOS, Linux, Windows via WSL or Git Bash):
curl -s "https://get.sdkman.io" | bash
sdk install groovy
groovy --version
On Windows without SDKMAN, download the binary zip from groovy-lang.org, unzip it and add its bin folder to your PATH.
Tip: If you write scripts for a specific platform — Boomi, Jenkins, Gradle — check which Groovy version it uses and install the same major version locally. Newer versions moved some classes between packages.
Three ways to run Groovy
1. groovyConsole — a playground window
groovyConsole
Type code in the top half, press Ctrl+R (Cmd+R on Mac), see the output below. Perfect for experiments.
2. groovysh — the interactive shell
groovysh
groovy:000> 24 * 8.5
===> 204.0
groovy:000> 'po-4471'.toUpperCase()
===> PO-4471
3. Scripts
Groovy doesn’t need a class or a main method. A file with statements is a program:
// hello.groovy — your first Groovy script. Run: groovy hello.groovy
println 'Hello, Groovy!'
def name = args ? args[0] : 'Groovy learner'
println "Welcome, $name!"
// Groovy runs Java too: any Java code is (almost always) valid Groovy
System.out.println("Java style works as well");
println "Java version: ${System.getProperty('java.version').split(/\./)[0]}+"
Run it:
groovy hello.groovy
groovy hello.groovy Chirag
Hello, Groovy!
Welcome, Groovy learner!
Java style works as well
Java version: 21+
Java vs Groovy at a glance
The same task in both languages — print the names of active customers, uppercased:
// Java
List<String> result = new ArrayList<>();
for (Customer c : customers) {
if (c.isActive()) {
result.add(c.getName().toUpperCase());
}
}
System.out.println(result);
// Groovy
println customers.findAll { it.active }*.name*.toUpperCase()
You’ll understand every symbol in that one-liner by the end of the closures and collection methods lessons.
Try it yourself
Write a script that prints the current date and time, then counts from 1 to 5 on one line.
Show a solution
println "Now: ${java.time.LocalDateTime.now()}"
println((1..5).join(' '))
(1..5) is a range — more about ranges in Lists, maps and ranges.
Key takeaways
- Groovy runs on the JVM, uses Java libraries and accepts most Java code.
- Install it with SDKMAN (or the zip) on top of a JDK.
- Use groovyConsole or groovysh to experiment; run files with
groovy file.groovy. - Scripts need no class or
mainmethod.