Groovy Cookbook

Most popular posts

Groovy Regular Expressions - The Definitive Guide (Part 1)

Welcome to "Groovy Regular Expressions - The Definitive Guide"! In the next 15 minutes, you are going to learn everything you need to start working productively with regular expressions in Groovy programming language. Let’s get started!

Tail-recursive methods in Groovy

Most of the object-oriented programmers prefer constructing algorithms using imperative style over using recursion. This is pretty obvious in the JVM ecosystem, where imperative iteration is much more efficient than recursive function call chain. However, what if I tell you that in Groovy you can take advantage of clean tail-recursive functions without sacrificing performance? Interested? Let’s deep dive into it.

GraalVM and Groovy - how to start?

GraalVM became one of the most popular topics in the JVM ecosystem. It promises the highest possible speed of running JVM-based programs (when compiled to native images), hand in hand with the smaller memory footprint. It sounds interesting enough to give it a try. And today we are going to play around a little bit with running simple Groovy program after compiling to a standalone native image.

Watch my YouTube videos


Groovy Tutorial | Writing Brainf**k interpreter | #groovylang


Groovy Tutorial | Closures - how to use them? | #groovylang


Groovy Tutorial | Groovy DSL Quickstart | #groovylang

Latest blog posts

Groovy: static propertyMissing and methodMissing methods - limitations and possible issues

Some time ago I have found another interesting Groovy related question on Stack Overflow. This time someone was asking about static variants of popular propertyMissing and methodMissing methods. The official Groovy documentation does not explain how to do it - it only explains how to add any static method through metaClass. Today we are going to learn how to define these methods in two different ways.

Groovy: dynamic types coercion and promotion - you have been warned!

Groovy is a very powerful language on a JVM platform and with this great power comes great responsibility. There are many language features that are not intuitive for many people that start using Groovy. One of these features is dynamic coercion and type promotion which may cause you a headache if you use it carelessly.

How to name Groovy script file?

Some time ago I have found a very interesting question on Stack Overflow about forbidden characters in Groovy script filenames. Let’s use it as an excuse to make a closer look at Groovy script files naming limitations - you will find out that there are none actually.

Groovy: split string and avoid getting IndexOutOfBoundsException

If you use Groovy for scripting or other similar tasks you probably faced a situation where you get an input as a text and you need to process it e.g. split by some delimiter and continue working with extracted values. In this post I will show you how to do it in 3 different ways.

Groovy script: closure does not modify @Field annotated variable

Recently I have answered a few questions on Stack Overflow related to Groovy scripts and how they work in combination with closures and delegated objects. Some of use cases may not be intuitive and today I’m gonna show you one of them and explain what happens under the hood.

Why "grails package" executes Config.groovy file?

This blog post is inspired by one of my recent Stack Overflow answers to following question: Grails: why is the Config.groovy file executed during compilation?. Here I’m going to show you step by step what makes grails package command executing Config.groovy script and how I’ve managed to find the answer to that question.