Blog

Blog

Hi all,

The Groovy team is very pleased to announce the first beta of the Groovy 2.3 release! 

Groovy 2.3.0-beta-1 is actually already a feature-complete beta, so the release cycle towards the final version will be very short. Furthermore, Grails 2.4 is looking forward to integrating it rapidly as well for its upcoming major release too! So you can expect a general availability version of Groovy in the coming weeks, as we’ll move directly in “release candidate” mode after this beta. But your feedback, as usual, will be very important for trying out this beta in your respective projects, to tell us about any problem you might encounter.

In this email, below, I’ll give you a few pointers regarding the scope of the release, but we’ll be fleshing out a more detailed release notes document in the coming days and weeks with more information.

Warning: this is a lengthy email, but you’ll get to see all the new stuff and improvements the Groovy team and contributors have been working on!

The key highlights of Groovy 2.3 are:

  • Official support for running Groovy on JDK 8

    This is the first version of Groovy to be officially compatible with JDK 8.

    JDK 8 and its interface default methods introduced some incompatibilities with a few methods of the Groovy Development Kit, so we had to adapt to the situation, introducing minor breaking changes for the affected methods and their outcome.

    Note that we’re not planning to backport the changes to older versions of Groovy, so if you want to run Groovy on JDK 8, you’ll have to upgrade to the shiniest version of Groovy!

  • Traits

    A major highlight for Groovy 2.3 is the introduction of the
    concept of traits.

    Traits are reusable components of behavior that you can make your class implement, and are an additional Object-Oriented concept alongside classes and interfaces.

    Groovy traits are stateful (unlike Java 8 interface default methods).

    They allow the composition of behavior without going into the “diamond inheritance” problem allowing you to decide which behavior prevails upon conflict.

    Traits support inheritance, thus a trait can extend another trait or implement an interface.

    Traits are compatible with static type checking and compilation, as well as our usual dynamic behavior. Trait mixed-in methods are actually “real” methods (ie. visible from Java as well) and not just dynamic.

    Traits can also be implemented at runtime with “as” or with “withTraits” if you just want to add behavior of a trait to an object you’re instantiating.

    You can find more information on traits in the exhaustive
    trait documentation.

  • New and updated AST transformations

    • @TailRecursive on methods adds tail recursion to methods which are recursive and call themselves at the last operation of the method body, which helps blowing up the stack with the recursive calls (GROOVY-6570).

    • @Sortable on classes implement comparison methods for you, according to the declaration order of your properties (GROOVY-6649).

    • @Delegate supports includes and excludes attributes so as to let you decide if certain methods should be included or excluded from the delegation (GROOVY-6329).

  • New NIO module for Java 7+

    On JDK 7 and beyond, you can benefit from the same methods as the ones of File, URLs, the various Stream classes, etc, but for the new NIO2 methods, like Path.

    See
    GROOVY-6377 and the pull request for some further hints of the new methods.

  • Various minor performance improvements across the board, for static compilation, the “invoke dynamic” backend, as well as “normal” dynamic Groovy

  • Drastic JSON parsing and serialization performance improvements

    The Rick / Andrey duo spent a fair amount of time optimizing our JSON support, making Groovy 2.3’s JSON support usually
    faster than all the JSON libraries available in the Java ecosystem.

    With
    JsonSlurper, you’ll be able to set different parser types depending on the kind of input you wish to parse, particularly if you know the size of the payload you expect to parse, or whether you want a more tolerant parser which accepts elements like comments which are not normally supported by the JSON specification (GROOVY-6546).

    On the output front, with
    JsonBuilder and StreamingJsonBuilder, which both use JsonOutput for output generation, the serialization has also been tremendously improved (GROOVY-6554).

  • Closure type parameter inference

    We closed a gap which forced you to type your closure parameters to get correct type inference with static type checking or static compilation enabled. In situations like the following, you would have to explicitly give the type of the parameter, but it’s no longer required:

    ['a','b'].each { it.toUpperCase() }

    In the signature of your methods taking closures as arguments, you’ll also be able to annotate the closure parameter with
    @ClosureParams to give additional hints to the type checker to infer the type of the parameters passed to your closure.

    You can also find more about this in Cédric’s blog post on
    closure parameter type inference.

  • New Markup template engine

    Groovy now has an additional template engine, in the form of the Markup template engine, which gives you a very fast template engine, based on the familiar Markup builder approach and notation, but also offering formatting options (indentation, escaping), internationalization, includes, as well as proposing type checked templates and models.

    More details about the new
    Markup template engine in the documentation (GROOVY-6596), as well as in Cédric’s blog, if you want to learn more about the “behind the scenes” stories!

  • Further Groovysh enhancements

Along with some slightly reduced startup time, Groovysh has seen new improvements in its code-completion capabilities:

  • GroovyConsole enhancements

    It is now possible to configure the font used by the console, and also to be able to run a selected snippet of code reusing the imports defined in your script making it easier to just run quick snippets of your script.

  • JUnit 4 GroovyAssert class

    The venerable
    GroovyTestCase (JUnit 3 based approach) has often been used as a base class for your test classes — unless you’ve been using the Spock testing framework, of course. One of the drawback of this class is that your test classes can’t extend your own classes, but must derive from GroovyTestCase to benefit from the additional assertion methods.

    Groovy 2.3 introduces the JUnit 4-friendly
    GroovyAssert, which is a convenient class offering the usual assertion methods of GroovyTestCase, but in the form of static methods that you can static import in your test class.

    We have not included the myriads of assertEquals method from GroovyTestCase as they have become useless with Groovy’s power assert, but it provides the handy shouldFail*() methods (
    GROOVY-6588).

  • ConfigSlurper

    ConfigSlurper just supported a single “environments” non-configurational conditional block, but you couldn’t let you define your own. With Groovy 2.3 you can also create your own ones too, for instance if you wanted to support “flavors” like OS variants (
    GROOVY-6383).

    In addition, the isSet() / hasSet() combo methods (
    GROOVY-4639) have been added so you can double check if a given node of your configuration has been defined. Before, whether the node wasn’t defined or containing null, you couldn’t differentiate either case easily.

  • @BaseScript class improvements

    @BaseScript is a fairly recent addition in Groovy, and it allowed to annotate a variable in your script to instruct the compiler to use a particular base script class for this script. Now we have another notation which is nicer as you can annotate an import or a package (GROOVY-6592) to indicate that base script class:

    @BaseScript(MyScript)
    import groovy.transform.BaseScript


    Additionally, base script classes can now use any abstract method for the script body. This means that you can implement the run() method to implement specific behavior like setup and tear down in tests (
    GROOVY-6585 and GROOVY-6615).

  • New style for the GroovyDoc documentation of Groovy and the GDK methods

    GroovyDoc has been updated with a new fresh and modern skin that will be part of the future visual identity of the Groovy website. Those style updates are also available by default for your own usage of GroovyDoc, making your own documentation nicer on the eye.

    You can have a look at the
    GroovyDoc documentation for Groovy 2.3.0-beta-1.

    We also took the opportunity to apply the same stylesheet to our “DocGenerator” tool which is responsible for the generation of the GDK documentation, showing the methods the Groovy library adds on top of the JDK classes.

    Please also have a look at the new
    restyled GDK documentation.

  • New documentation

    We are still working on the brand
    new documentation for Groovy (in Asciidoc(tor) format), so you can already have a glimpse at what’s already covered or not.

    We’re looking forward for help for fleshing out the various TBD (To Be Done) sections of the documentation, as it’s a gigantic taks to re-document each and every aspect of the language and its libraries! So please shout if you want to
    contribute to the new documentation! All help is warmly welcome!

  • Dependency upgrades

    • Gradle 1.10 for building Groovy

    • ASM 5.0.1 library for generating our bytecode (also needed for our JDK 8 support)

    • JLine 2.11 and JANSI 1.11 library for Groovysh


Groovy wouldn’t be what it is without your support, your bug reports and feature requests, your contributions and pull requests, so big thanks to all those who contributed to this release in a way or another, including the usual suspects of the core team (Jochen, Paul, Cédric and myself), but also André (documentation, GroovyAssert, Groovy Console), Andres (Config slurper, @Sortable with Paul), Tim, Pascal (ConfigSlurper), Johanes (@TailRecursive), Paolo (new NIO module), Thibault (groovysh), Rick and Andrey (for the JSON support), Jim (base script class), Damien (GroovyDoc / GDK styling), Kenneth and several others I’ve forgotten to mention!

And in honor of this first beta release of Groovy 2.3, Cédric even decided to put his birthday on the same day, so happy birthday Cédric, and great work on this release!

We’re looking forward to your feedback running this beta to its pace!

It’s important to make this 2.3 release rock solid!

Download Groovy 2.3-beta-1 and have a look at the JIRA release notes for additional details on issues and bug fixes closed.


Keep on groovy’ing!

 


Groovy Weekly #14

The latest does of fresh news for the Groovy community is out: Groovy Weekly #14

Groovy Weekly #9
The 9th edition of the Groovy Weekly column is out:
You can actually receive it right in your inbox by subscribing to the mailing-list:
Please share the news with your friends and colleagues, and spread the news about this column!
Also, don't forget that you can contribute news too!
Through this Google form here: http://bit.ly/groovyweekly
Groovy Weekly #8

The latest Groovy Weekly column is out, in its 8th edition:

http://glaforge.appspot.com/article/groovy-weekly-8

The 6th edition of the Groovy Weekly column is out!

Get the latest news of the Groovy ecosystem.

The Groovy Weekly 5th edition is out!

The big news of this edition is probably the ongoing success of Groovy, demonstrated by the tremendous growth in downloads for Groovy, from 1.7 million downloads in 2012 up to 3 million in 2013!

Here's the fourth edition of our Groovy Weekly column, full of news of the Groovy ecosystem!
Don't forget you can contribute to this weekly column of Groovy news, and that you can subscribe through a newsletter to get the news directly delivered to your inbox.
The third Groovy Weekly column and the first for the new year has just been published:
Don't forget you can contribute to this weekly column of Groovy news, and that you can subscribe through a newsletter to get the news directly delivered to your inbox.

The "Groovy Weekly" column has launched!

On a weekly basis, you'll be able to get all the latest news, filtered and categorized, about the Groovy ecosystem, with information such as the latest releases, upcoming events, news about various projects of the Groovy world, job postings, interesting tweets or mailing-list posts, and more. If you want to get up-to-date on everything Groovy, that's what you'll have to read!

The first two editions have been published here:

Note that going forward, as we're working on a redesigned Groovy website, the blog posts will likely migrate to the future Groovy blog instead.

The release of the column should take place every week, and will be announced via different means: mailing-list, tweeter, Google+, and on this blog. But if you prefer to receive this information directly in your inbox, you can subscribe to the Groovy Weekly newsletter.

Also, this column is yours! If you want to contribute news items, don't hesitate to do so via the contribution form.

We're looking forward to hearing about your feedback about this weekly column!

And on behalf of the Groovy team, we'd like to wish you a very Groovy New Year!

 

Hot on the heels of the release of our new major release of Groovy 2.2.0, we're delivering a first bug fix release with Groovy 2.2.1.

As a refresher, be sure to have a look at the release notes for Groovy 2.2.0 to remember the various improvements and enhancements that got integrated.

Some fixes didn't make it in the RC phase, and additional further fixes appeared upon wider usage of 2.2.0 in the wild. Those fixes cover various areas, such as issues with Groovysh, a couple VerifyErrors, some fixes to our AST transformations, a problem with the new implicit closure coercion mechanism. For more details, you can have a look at the full JIRA release notes.

And go download Groovy 2.2.1!

Thanks a lot for your attention and your contributions.

Groovy 2.2 is released

Hi all,

This is with great pleasure that the Groovy team is announcing today the release of Groovy 2.2, the latest version of the Groovy programming language.

Groovy 2.2 features:

 

  • Implicit closure coercion
  • @Memoized AST transformation for methods
  • Define base script classes with an annotation
  • New DelegatingScript base class for scripts
  • New @Log variant for the Log4j2 logging framework
  • @DelegatesTo with generics type tokens
  • Precompiled type checking extensions
  • Groovysh enhancements
  • Bintray's JCenter repository
  • OSGi manifests for the “invoke dynamic” JARs
  • And other minor bug fixes, enhancements and performance improvements

You can read more detailed release notes as well as have a look at all the JIRA issues fixed.

Then download Groovy 2.2 while it's hot!

Thanks a lot to all the users, contributors, developers who contributed to that release!

Hi all,

The Groovy team is pleased to announce the third release candidate for Groovy 2.2.

We've fixed a few issues and improved the closure coercion capability.

Here's the JIRA changelog and you can download RC-3 at the usual location.

Thanks for your feedback.

The Groovy team is happy to announce the release of the release candidate of Groovy 2.2, as well as a bug-fix release for Groovy 2.1.8.

As you can guess with this release candidate, the final version of Groovy 2.2 is fast approaching, and we'd be happy to get as much feedback on this release as possible, to squash potential bugs before the general availability of 2.2. So please be sure to test your applications with this release candidate.

For both releases, we've made a small update to the default Grab configuration which is to use Bintray's JCenter repository as the first in the chain of resolvers, as Bintray's JCenter repository is noticeably faster and more responsive than Maven Central, offers dependencies always with their checksums, and stores and caches dependencies it wouldn't have for faster delivery the next time a dependency is required. This should make your scripts relying on @Grab faster when downloading dependencies for the first time.

An interesting feature in the release candidate only is the ability for scripts to define their base script class. All scripts usually extend the groovy.lang.Script abstract class, but it's possible to set up our own base script class extending Script through CompilerConfiguration. A new AST transformation is introduced in Groovy 2.2 which allows you to define the base script class as follows:

Again for 2.2, a new @Log variant has been added to support Log4j2, with the @Log4j2 AST transformation:

 

For more details on those two releases, please have a look at the release notes on JIRA:

Go download Groovy 2.1.8 and test drive 2.2.0-rc-1 while they're hot, in the download area!

Thanks a lot for your contributions to those releases, in terms of bug reports, discussions on the mailing-lists, code contributions and pull requests!

Keep on groovy'ing!

 

The Groovy team is happy to announce the releases of the second beta of Groovy 2.2, along with a bug fix release of Groovy 2.1.7.

We're close to moving towards RC mode for the upcoming Groovy 2.2 release, and we'd be happy to hear about your feedback about this new version when used in your projects. Please have a moment to test it against your code, and tell us if you notice any problem or regression.

Groovy 2.2.0-beta-2 is pretty much feature complete by now, with only a few minor improvements, and both 2.2.0-beta-2 and 2.1.7 contain a great deal of bug fixes around our static type checker and compilation support.

You can have a look at the JIRA release notes for the details:

Those two Groovy versions are available in the download area of the website.

Thanks a lot to all those who contributed to this release, and we're looking forward to hearing your feedback about the upcoming 2.2!

We'd also be happy to see you at next week's SpringOne2GX conference if you're around! So don't hesitate to come and say hi to the Groovy team members who will be present — and there are quite a few of us there!

 

The Groovy development team is pleased to announce the release of the first beta of Groovy 2.2, along with a bug fix release of Groovy 2.1.6.

Both Groovy 2.1.6 and 2.2.0-beta-1 contain fixes for the recently discovered JavaDoc vulnerability, that also affected GroovyDoc.

Let me highlight a few interesting points in this 2.2 beta.

Implicit closure coercion

Java 8 will feature lambdas, which are similar to Groovy’s closures. One particular aspect which is interesting with lambdas is how they are converted transparently by Java to interface types that contain one single abstract method. With Groovy closures, except for a few cases, we have to explicitly use the as operator to do the coercion. In Groovy 2.2, we are allowing the same transparent closure coercion to happen, but without the explicit as type coercion, and furthermore, we make it possible to work as well with abstract classes as well.

 

Notice how the closure is coerced into a Predicate instance. Without that new capabilities, we would have had to write the following instead:

That way, Groovy closure coercion to SAM types is as concise as Java 8 lambda closure convertion.

@Memoized AST transformation for methods

Similarly to our Closure memoization capability, you can now annotate your methods with the new @Memoized annotation. It will use the same underlying cache solution used for closures, and will cache the result of previous executions of the annotated method with the same entry parameters.

 

 

New DelegatingScript base class for scripts

With the CompilerConfiguration class that you pass to GroovyShell (as well as GroovyClassLoader and others), you can define a base script class for the scripts that will be compiled with that shell. It’s handy to share common methods to all scripts.

For DSL purposes, it’s interesting to actually delegate the method calls and unbound variable assignments to a different object than the script itself, thanks to the new DelegatingScript.

To make it more concrete, let’s have a look at the following configuration script:

 

 

@DelegatesTo with generics type tokens

The @DelegatesTo annotation, introduced in Groovy 2.1 that helps the type checker, IDEs, tools, to provide better support for DSLs using closure delegation strategies, works with generics token types as well. You can tell Groovy that the delegatee is of the type of the generics component:

 

Note the genericTypeIndex attribute of @DelegatesTo that points at the index of the generic component. Unfortunately, as the generic placeholders are not kept at the bytecode level, it’s impossible to just reference T, and we had to use an index to point at the right type.

Precompiled type checking extensions

The static type checking extensions introduced in Groovy 2.1 were working solely with non-compiled scripts. But with this beta, you can also specify a fully-qualified name of the precompiled class implementing your extension:

Type checking extensions now also support two more events: ambiguousMethods and incompatibleReturnType. 

Groovysh enhancements

Groovysh has been expanded with various enhancements:

  • support for code completion in various places, like imports, package names, class names, variable names, parameter names, keywords, etc.

  • a doc command allows you to open the relevant JavaDoc and Groovy GDK web pages to have more information for a given class, for example try in Groovysh:
    doc java.util.List

  • you can complete file names inside strings, particularly handy for your scripting tasks where you want to open a file with new File("data.|”) (where the pipe character is the position of your cursor), and then hit the TAB key to have the completion of the file name

OSGi manifests for the “invoke dynamic” JARs

If you’re using Groovy in the context of an OSGi container, the Groovy JARs contained the right OSGi metadata information in its manifest. However, it wasn’t the case for the “invoke dynamic” JARs, as the underlying library used by the Gradle OSGi plugin wasn’t supporting JDK 7 bytecode. Fortunately, this deficiency has been fixed, the Gradle OSGi plugin updated, and we’re now able to have our “indy” JARs work fine under OSGi has well.

Those changes have not yet been backported to the Groovy 2.1.x branch, but will likely be. We’re looking forward to hearing your feedback, for those using Groovy and OSGi.

For more details about the various bug fixed in those releases, please have a look at the JIRA release notes:

And then, go download Groovy 2.2-beta-1 and Groovy 2.1.6 on our Download area while it's hot!

Thanks a lot for all your contributions, and we’re looking forward to your feedback on those releases.