Groovy Cheat Sheet
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
A single-page, colour-coded summary of the Apache Groovy language, written against Groovy 6.0 (6.0.0, released 2026-09-22; JDK 17 or newer) and checked on 2026-10-14, with additions after Groovy 4.0 labelled by release — running scripts and the tools, syntax and optional elements, the six string forms and GString laziness, numbers and the Groovy Truth, collection literals and the most used GDK methods, the operator grid with the operator-to-method table and the precedence ladder, control flow including switch expressions, closures with currying, composition and delegation, classes with the generating AST transformations, traits, records and sealed types, static typing, metaprogramming, file and process one-liners, JSON, XML, YAML, TOML, CSV, SQL and GINQ, the Groovy 6.0 concurrency features, DSLs and embedding, testing, and a strip of legacy idioms and their modern replacements — handy for quick memorization or as a downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — Groovy Reference.
Getting started — Getting Started, Differences with Java, Groovy & Other Languages, Running Scripts & the groovy Command, and groovysh & groovyconsole.
Syntax and fundamentals — Lexical Structure, Comments, Keywords & Identifiers, Strings & GStrings, Numbers & Numeric Literals, Booleans & the Groovy Truth, Lists & Arrays, Maps, Ranges, Variables, Typing, def, var & val, and Program Structure, Packages, Imports & Scripts.
Operators — Operators: Arithmetic, Relational & Logical, Object Operators, Regular Expressions, and Operator Overloading.
Control structures and semantics — Control Structures, Exceptions & Error Handling, Assertions & Power Assert, Type Coercion & Promotion, and Optionality.
Object orientation — Classes, Fields & Properties, Methods, Constructors & Parameters, Inheritance, Interfaces & Generics, Traits, Records & Sealed Types, and Enums & Annotations.
Closures and functional programming — Closures, Closure Delegation: Owner, Delegate & This, and Functional Programming.
Typing — Static Type Checking & @CompileStatic, Type Checking Extensions, and Built-in Type Checkers.
The GDK — GDK Overview & Object Methods, Working with Collections, Files I/O & Paths, External Processes, and Dates & Times.
Metaprogramming — Runtime Metaprogramming & the MOP, Metaclasses, ExpandoMetaClass & Categories, Extension Modules, AST Transformations: Code Generation & Class Design, AST Transformations: Logging, Safety, Concurrency & Directives, and Writing AST Transformations & Macros.
Concurrency — Async/Await, Generators, Channels & Structured Concurrency, Parallel Collections & Dataflow, and Actors, Agents & Active Objects.
Data and module guides — JSON, XML Parsing, GPath & Security, XML: Creating & Manipulating, YAML & TOML, CSV & Markdown, Databases with Groovy SQL, GINQ: SQL-like Collection Queries, Template Engines, HTTP Client with HttpBuilder, and Builders.
DSLs and scripting — Domain Specific Languages and Compilation Customizers & Secure Scripting.
Integration and tools — Integrating Groovy into Java Applications, Compiling with groovyc & Joint Compilation, Build Tools: Gradle, Maven & Ant, Grape Dependency Management, GroovyDoc, Groovlets, Servlets & JMX, and Performance, invokedynamic & Native Images.
Testing — Testing with JUnit & Groovy Test, Testing with Spock & Geb, and Design by Contract with groovy-contracts.
Practice and reference — Style Guide & Idioms, Design Patterns in Groovy, What’s New & Migrating from Older Versions, and Ecosystem & Groovy in Other Tools.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.