Idea logo

The IntelliJ IDEA Blog

The Capable & Ergonomic Java IDE by JetBrains


Groovy Improvements in IntelliJ IDEA 2018.2

IntelliJ IDEA 2018.2 comes with support for Groovy 2.5 features, and for the current draft of the Groovy 3.0 specification (note that Groovy 3.0 is in alpha and functionality may change in the future).

Groovy 2.5

IntelliJ IDEA 2018.2 supports new features in Groovy 2.5 like the AST Transformations Annotations. If, for example, you want to call a method with named parameters (and you don’t want to declare that method as taking a Map, which is one way Groovy provides Named Arguments), you can use the @NamedParam attribute.

Consider a method like this one:

String fullName(String lastName, @NamedParam String firstName) {
    "$firstName $lastName"

This method can be called with two String parameters, or you can use the parameter name.  This can be particularly useful with methods that multiple parameters of the same type as it’s much clearer what each value represents.

Groovy 3.0

IntelliJ IDEA 2018.2 lets you write valid Groovy 3.0 code.  For example, Groovy 3.0 supports some classic Java syntax, like do while

Java 8 features also make it into this version of Groovy, for example now you can use method references in Groovy code.


You can also add default methods to interfaces in Groovy 3.0. These will give you a default implementation of a method if the method isn’t implemented in a subclass, or you can override the functionality as you would with any superclass.

Groovy 3.0 adds a simpler way to negate the instanceof and in operators.  Previously, you had to put the expression inside brackets and negate the whole expression, but now you simply have to put the exclamation mark in front of the keyword itself to negate it


Also new is a shorthand way to assign a default value if no value is present, via the Elvis assignment shorthand ?=. Instead of having to do something like

value = value ?: 'Some Default Value'

you can simply do:
value ?= 'Some Default Value'

For example:


Existing versions of Groovy let you safely navigate objects that might have null values, but this was not supported for arrays.  Groovy 3.0 adds this feature for array indexes so it’s now possible to refer to an index on an array that might be null, or a value from an array that might be null, without the risk of throwing a NullPointerException.


Groovy 3.0 has added the === and !== equality operators which you can use to check if two variables are actually the same object. This is the equivalent of using the is() method.


All code examples in this blog post are either the same as, or adapted from, the examples in the current Groovy 3.0 release notes. Given that the release is still in alpha, the examples in the release notes may change, and the examples in this blog post might stop working. Groovy 3.0 is a work in progress, and as such IntelliJ IDEA’s support will also progress and possibly change.  Watch this blog for more updates!


Comments below can no longer be edited.

3 Responses to Groovy Improvements in IntelliJ IDEA 2018.2

  1. Avatar

    Pradeep says:

    December 27, 2018

    Complete implementation of Groovy 3 is still not available.

    This is a ticket raised 10 months back (precisely on March 12, 2018) with pending implementations.

    • Trisha Gee

      Trisha Gee says:

      January 23, 2019

      This is true, and of course we are working on it. But also bear in mind that Groovy 3 is still in alpha, and implementing support for language features that may change is potentially wasteful. Look at how many frameworks, e.g. Gradle, waited for Java 9 to stabilise before creating a version that fully worked with Java 9. And see also the fact that Raw String Literals were just recently pulled from Java 12 – implementing support for features before a language is ready is quite risky.

      • Avatar

        Pradeep says:

        January 23, 2019

        Thanks for acknowledging my comment.
        I simply pointed out that there are features which are pending/work-in-progress. And yes I do understand that official release of version 3.0 is not done yet and yes rework is a costly affair !!

Discover more