Apache Groovy 5.0 brings compact source notations and Jakarta servlets
The latest major release of the Apache programming language for the Java Virtual Machine offers numerous simplifications and new functions.
(Image: Zakharchuk/Shutterstock.com)
- Manuel Masiero
The Apache Software Foundation has presented version 5.0 of the Groovy programming language. The latest major release of the alternative JVM language (Java Virtual Machine) includes numerous improvements and bug fixes, as well as several new functions. These include extended script variants, simpler creation of web content and improved type checking.
The extended script variants of Groovy 5.0, which are based on JEP 512 and are intended for JDK 25, include a compact source notation for Java classes. This allows a main method to be created without an explicit class definition. If, for example, the classic “Hello, World!” is to appear on the screen, this can be done in a traditional script file with println 'Hello, World!', and with Groovy 5.0 it can now also be expressed as follows:
void main() { // Java JDK25 (also Groovy 5+)
IO.println("Hello, World!");
}
Alternatively, developers can also create the “Hello, World!” example using the instance run method of JEP 512. Its implicit class definition improves Java compatibility and also makes it possible to use method and class annotations that are difficult to implement with traditional Groovy scripts.
def run() {
println 'Hello, World!'
}
Videos by heise
Jakarta EE support for web content
With Groovy 5.0, the groovy-servlet of Jakarta EE can be handled more flexibly, which provides more flexibility in the creation of web content. Developers can write servlets as Groovy classes or as Groovy Server Pages (GSPs), which typically combine HTML with Groovy logic. In addition, the groovy-servlet can also be used to create Groovy scripts called Groovlets (see example below). If older Javax EE classes are required, these can be integrated via the javax classifier.
html.html {
head {
title 'My first Groovlet'
}
body { h1 'Welcome to Groovlets!' }
}
More details on the most important new features of Groovy 5.0 are summarized in the release notes. A list of all bug fixes and improvements can be found in the changelog. Groovy 5.0 can be downloaded from the project website; JDK 17 or higher is required to build it. The version currently has beta status, which is why the Apache Software Foundation recommends that users do not yet use it in production environments.
(kbe)