Skip to content

Groovy Tutorials — Complete Beginner to Advanced Guide

In this tutorial series, you'll learn Groovy from the ground up. Groovy is a dynamic optionally-typed language for the JVM -- combining Java power with scripting productivity, used by Gradle, Jenkins pipelines, and Grails web apps.

1. What is Groovy?
History, JVM, dynamic typing
2. GDK
Extensions, collections, strings
3. Closures
Parameters, scope, delegation
4. GPars
Parallelism, actors, dataflow
5. XML Builders
MarkupBuilder, XmlSlurper
6. JSON
JsonSlurper, JsonOutput
7. Markup & DSLs
Builder patterns, HTML
8. Metaprogramming
MOP, metaclass, categories
9. Grails
Full-stack, GORM, scaffolding
10. Spock Testing
Specifications, mocks, data tables
11. Gradle DSL
Build scripts, tasks, plugins
12. AST Transformations
@ToString, @Canonical, custom
13. GStrings & Strings
Interpolation, multiline, regex
14. Collections
List, Map, Range, spread
15. DSL Building
Builder pattern, custom DSLs
16. Database
Groovy SQL, DataSource, GORM
17. Web Services
HTTP, REST, JSON APIs
18. File I/O
eachLine, text, ant DSL
19. Swing Builders
GroovySwing, UI, events
20. Mini Projects
CSV report, web scraper, build tool

Let's begin with Lesson 1.

Published Topics

Groovy Guide — What is Groovy? Scripting for the JVM

Groovy is a dynamic optionally-typed language for the JVM combining Java power with scripting productivity, featuring closures, builders, GStrings, and AST transforms.

✓ Live

Groovy GDK Guide — Enhanced Standard Library and Collection Methods

The Groovy Development Kit extends Java's standard library with convenience methods on strings, collections, files, and more -- enabling concise and expressive code.

✓ Live

Groovy Guide — GroovyBeans: Properties and JavaBeans

GroovyBeans provide automatic property accessors, simplified object creation, and seamless JavaBeans integration with compact syntax.

✓ Live

Groovy Guide — Closures: Functional Building Blocks

Groovy closures are anonymous code blocks that capture variables, accept parameters, and can be passed as first-class values to methods.

✓ Live

Groovy Guide — Strings: Interpolation and Advanced Features

Groovy strings support interpolation, multi-line strings, GStrings, and extensive string methods for flexible text manipulation.

✓ Live

Groovy Guide — Collections: Lists, Maps, and Ranges

Groovy extends Java collections with literal syntax, operator overloading, and functional methods for concise list, map, and range operations.

✓ Live

Groovy Guide — Control Flow: Conditionals and Loops

Groovy extends Java control flow with simplified if/else, powerful switch cases, and idiomatic iteration patterns for cleaner code.

✓ Live

Groovy Guide — GPath: Navigating Object Graphs

GPath is Groovy's expression language for navigating nested object graphs, collections, and XML/JSON structures using dot notation and star operators.

✓ Live

Groovy Guide — Builders: Constructing Hierarchical Structures

Groovy builders provide a DSL for constructing nested structures like XML, JSON, HTML, and Swing UIs using hierarchical closure syntax.

✓ Live

Groovy Guide — XML: Parsing and Generating XML

Groovy provides XmlSlurper for parsing, XmlParser for detailed access, and MarkupBuilder for generating XML with minimal code.

✓ Live

Groovy Guide — JSON: Parsing and Generating JSON

Groovy JSON processing uses JsonSlurper for parsing, JsonOutput for generation, and JsonBuilder for constructing JSON structures.

✓ Live

Groovy Guide — File I/O: Reading and Writing Files

Groovy extends Java file I/O with convenience methods on File, Reader, and InputStream for reading, writing, and processing files succinctly.

✓ Live

Groovy Guide — SQL: Database Access Made Simple

Groovy SQL provides a simplified JDBC wrapper with closure-based result processing, named parameters, and data set operations for database access.

✓ Live

Groovy Guide — Templates: Generating Text and HTML

Groovy templates use GString-like syntax for generating dynamic text content, supporting layouts, includes, and iteration for web pages and reports.

✓ Live

Groovy Guide — Testing: Unit Testing with JUnit and Groovy

Groovy testing combines JUnit's structure with Groovy's concise assertions, power assertions, and mock support for comprehensive test suites.

✓ Live

Groovy Guide — Spock: Specification Testing Framework

Spock is a testing framework for Groovy and Java that uses specification-style tests with given-when-then blocks, built-in mocking, and data-driven testing.

✓ Live

Groovy Gradle Integration — Build Automation and Custom Tasks

Groovy is the default scripting language for Gradle build automation, enabling custom tasks, plugins, and build logic for Android and Java projects.

✓ Live

Groovy MOP — Meta-Object Protocol and Metaprogramming

Groovy's Meta-Object Protocol enables runtime interception of method calls, property access, and class behavior modification through its metaprogramming API.

✓ Live

Groovy Categories — Scoped Method Injection and DSL Building

Groovy categories provide a scoped mechanism to add new methods to existing classes within use blocks, ideal for DSL creation and temporary extensions.

✓ Live

Groovy Mixins — Runtime Behavior Composition

Groovy mixins inject methods from one class into another at runtime, enabling flexible composition patterns without traditional inheritance.

✓ Live

Groovy Delegation — @Delegate and Method Forwarding Patterns

Groovy's @Delegate annotation automatically forwards method calls to a delegate object, enabling composition-based design with minimal boilerplate code.

✓ Live

Groovy Traits — Reusable Behavior Composition

Groovy traits are reusable behavior units that provide method implementations and state, supporting multiple inheritance of behavior without the diamond problem.

✓ Live

Groovy Command Chains — Fluent DSL and Builder Syntax

Groovy command chains eliminate punctuation between method calls, enabling natural-language DSLs and fluent builder APIs without dots or parentheses.

✓ Live

Groovy Operator Overloading — Custom Operators for Cleaner Code

Groovy operator overloading maps operators like +, *, and [] to specific methods, enabling custom types with intuitive mathematical and collection syntax.

✓ Live

Groovy Scripting — Writing Scripts and Automating Workflows

Groovy scripting enables writing executable scripts without class declarations, with bindings, command-line arguments, and seamless Java integration for automation.

✓ Live

Groovy AST Transformations — Compile-Time Metaprogramming

Groovy AST transformations modify the abstract syntax tree during compilation, enabling boilerplate reduction and compile-time code generation through annotations.

✓ Live

Groovy Grape — Script Dependency Management

Groovy Grape (@Grab) lets scripts declare Maven dependencies inline, automatically resolving and downloading libraries from remote repositories at runtime.

✓ Live

GroovyServ — Faster Script Startup for Groovy

GroovyServ is a daemon that reduces Groovy script startup time by keeping the JVM warm across invocations, enabling near-instant script execution.

✓ Live

Groovy Classes from Java — Using Groovy in Java Projects

Groovy classes compile to JVM bytecode and can be used directly from Java, enabling gradual adoption of Groovy's productivity features in existing projects.

✓ Live

Groovy Ecosystem — Frameworks, Tools and Community

The Groovy ecosystem includes Grails web framework, Spock testing, Gradle build tool, GPars concurrency, and Ratpack for asynchronous web applications.

✓ Live

All 30 topics in Groovy Tutorials — Complete Beginner to Advanced Guide are published.