Skip to content
AgileLogics
4 min read

What Is Groovy?

Apache Groovy is a dynamic, optionally typed language for the Java Virtual Machine (JVM). It was started in 2003 by James Strachan, joined the Apache Software Foundation in 2015, and is used today by millions of developers — often without noticing, because every Gradle build script and Jenkins pipeline written in the classic style is Groovy code.

def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']

languages.findAll { it.size() <= 5 }
         .each { println "$it has ${it.size()} letters" }
Java has 4 letters
Scala has 5 letters

Its defining traits:

  • Java-friendly — almost any Java code is also valid Groovy, and Groovy uses the same classes, libraries, and JVM as Java. You can call Java from Groovy and Groovy from Java with no glue code.
  • Concise — no semicolons, optional parentheses and types, literal syntax for lists and maps, and closures (blocks of code you can pass around) everywhere.
  • Dynamic or static — your choice — by default, method calls are resolved at runtime, which enables metaprogramming and DSLs. Add @CompileStatic and the same code is type-checked and compiled like Java.
  • Scripting-ready — a .groovy file can be a script with no class and no main method, run directly with the groovy command.
  • Batteries included — JSON, XML, YAML, templates, SQL, and a command-line parser ship with the language.

This course teaches Groovy 6 (examples were run on Groovy 6.0.0 with Java 21). Almost everything also works on Groovy 4 and 5, which many tools still bundle; where a feature is newer, the lesson says so.