James Strachan first talked about the development of Groovy on his blog in August 2003.5 In March 2004, Groovy was submitted to the JCP as JSR 2416 and accepted by ballot. Several versions were released between 2004 and 2006. After the Java Community Process (JCP) standardization effort began, the version numbering changed, and a version called "1.0" was released on January 2, 2007. After various betas and release candidates numbered 1.1, on December 7, 2007, Groovy 1.1 Final was released and immediately renumbered as Groovy 1.5 to reflect the many changes made.
In 2007, Groovy won the first prize at JAX 2007 innovation award.7 In 2008, Grails, a Groovy web framework, won the second prize at JAX 2008 innovation award.8
In November 2008, SpringSource acquired the Groovy and Grails company (G2One).9 In August 2009 VMware acquired SpringSource.10
In April 2012, after eight years of inactivity, the Spec Lead changed the status of JSR 241 to dormant.11
Strachan had left the project silently a year before the Groovy 1.0 release in 2007. In Oct 2016, Strachan stated "I still love groovy (jenkins pipelines are so groovy!), java, go, typescript and kotlin".12
On July 2, 2012, Groovy 2.0 was released, which, among other new features, added static compiling and static type checking.
When the Pivotal Software joint venture was spun-off by EMC Corporation (EMC) and VMware in April 2013, Groovy and Grails formed part of its product portfolio. Pivotal ceased sponsoring Groovy and Grails from April 2015.13 That same month, Groovy changed its governance structure from a Codehaus repository to a Project Management Committee (PMC) in the Apache Software Foundation via its incubator.14 Groovy graduated from Apache's incubator and became a top-level project in November 2015.15
On February 7, 2020, Groovy 3.0 was released.16 Version 4.0 was released on January 25, 2022.17
Most valid Java files are also valid Groovy files. Although the two languages are similar, Groovy code can be more compact, because it does not need all the elements that Java needs.18 This makes it possible for Java programmers to learn Groovy gradually by starting with familiar Java syntax before acquiring more Groovy programming idioms.19
Groovy features not available in Java include both static and dynamic typing (with the keyword def), operator overloading, native syntax for lists and associative arrays (maps), native support for regular expressions, polymorphic iteration, string interpolation, added helper methods, and the safe navigation operator ?. to check automatically for null pointers (for example, variable?.method(), or variable?.field).20
Since version 2, Groovy also supports modularity (shipping only the jars that the project uses, thus reducing the size of Groovy's library), type checking, static compilation, Project Coin syntax enhancements, multicatch blocks and ongoing performance enhancements using the invokedynamic instruction introduced in Java 7.21
Groovy natively supports markup languages such as XML and HTML by using an inline Document Object Model (DOM) syntax. This feature enables the definition and manipulation of many types of heterogeneous data assets with a uniform and concise syntax and programming methodology.
Unlike Java, a Groovy source code file can be executed as an (uncompiled) script, if it contains code outside any class definition, if it is a class with a main method, or if it is a Runnable or GroovyTestCase. A Groovy script is fully parsed, compiled, and generated before executing (similar to Python and Ruby). This occurs under the hood, and the compiled version is not saved as an artifact of the process.22
GroovyBeans are Groovy's version of JavaBeans. Groovy implicitly generates getters and setters. In the following code, setColor(String color) and getColor() are implicitly generated. The last two lines, which appear to access color directly, are actually calling the implicitly generated methods.23
Groovy offers simple, consistent syntax for handling lists and maps, reminiscent of Java's array syntax.24
Groovy offers support for prototype extension through ExpandoMetaClass, Extension Modules (only in Groovy 2), Objective-C-like Categories and DelegatingMetaClass.25
ExpandoMetaClass offers a domain-specific language (DSL) to express the changes in the class easily, similar to Ruby's open class concept:
Groovy's changes in code through prototyping are not visible in Java, since each attribute/method invocation in Groovy goes through the metaclass registry. The changed code can only be accessed from Java by going to the metaclass registry.
Groovy also allows overriding methods as getProperty(), propertyMissing() among others, enabling the developer to intercept calls to an object and specify an action for them, in a simplified aspect-oriented way. The following code enables the class java.lang.String to respond to the hex property:
The Grails framework uses metaprogramming extensively to enable GORM dynamic finders, like User.findByName('Josh') and others.26
Groovy's syntax permits omitting parentheses and dots in some situations. The following groovy code
can be written as
enabling the development of domain-specific languages (DSLs) that look like plain English.
Although Groovy is mostly an object-oriented language, it also offers functional programming features.
According to Groovy's documentation: "Closures in Groovy work similar to a 'method pointer', enabling code to be written and run in a later point in time".27 Groovy's closures support free variables, i.e. variables that have not been explicitly passed as a parameter to it, but exist in its declaration context, partial application (that it terms 'currying'28), delegation, implicit, typed and untyped parameters.
When working on Collections of a determined type, the closure passed to an operation on the collection can be inferred:
A group of expressions can be written in a closure block without reference to an implementation and the responding object can be assigned at a later point using delegation:
Usually called partial application,29 this Groovy feature allows closures' parameters to be set to a default parameter in any of their arguments, creating a new closure with the bound value. Supplying one argument to the curry() method will fix argument one. Supplying N arguments will fix arguments 1 .. N.
Curry can also be used in the reverse direction (fixing the last N arguments) using rcurry().
Groovy also supports lazy evaluation,3031 reduce/fold,32 infinite structures and immutability,33 among others.34
On JavaScript Object Notation (JSON) and XML processing, Groovy employs the Builder pattern, making the production of the data structure less verbose. For example, the following XML:
can be generated via the following Groovy code:
and also can be processed in a streaming way through StreamingMarkupBuilder. To change the implementation to JSON, the MarkupBuilder can be swapped to JsonBuilder.35
To parse it and search for a functional language, Groovy's findAll method can serve:
In Groovy, strings can be interpolated with variables and expressions by using GStrings:36
GStrings containing variables and expressions must be declared using double quotes.
A complex expression must be enclosed in curly brackets. This prevents parts of it from being interpreted as belonging to the surrounding string instead of to the expression:
Expression evaluation can be deferred by employing arrow syntax:
According to Groovy's own documentation, "When the Groovy compiler compiles Groovy scripts and classes, at some point in the process, the source code will end up being represented in memory in the form of a Concrete Syntax Tree, then transformed into an Abstract Syntax Tree. The purpose of AST Transformations is to let developers hook into the compilation process to be able to modify the AST before it is turned into bytecode that will be run by the JVM. AST Transformations provides Groovy with improved compile-time metaprogramming capabilities allowing powerful flexibility at the language level, without a runtime performance penalty."37
Examples of ASTs in Groovy are:
among others.
The testing framework Spock uses AST transformations to allow the programmer to write tests in a syntax not supported by Groovy, but the relevant code is then manipulated in the AST to valid code.38 An example of such a test is:
According to Groovy's documentation, "Traits are a structural construct of the language that allows: composition of behaviors, runtime implementation of interfaces, behavior overriding, and compatibility with static type checking/compilation."
Traits can be seen as interfaces carrying both default implementations and state. A trait is defined using the trait keyword:
Then, it can be used like a normal interface using the keyword implements:
Traits allow a wide range of abilities, from simple composition to testing.
Notable examples of Groovy adoption include:
Many integrated development environments (IDEs) and text editors support Groovy:
There is one alternative implementation of Groovy:
"Groovy 2.0 Performance compared to Java". 25 Aug 2012. http://objectscape.blogspot.com.br/2012/08/groovy-20-performance-compared-to-java.html ↩
"Java vs Groovy2.0 vs Scala Simple Performance Test". 10 Jul 2012. Archived from the original on 10 December 2012. Retrieved 7 October 2012. https://web.archive.org/web/20121210210126/http://blog.evan-wong.com/2012/07/java-vs-groovy20-vs-scala-simple.html ↩
"Groovy 2.4 And Grails 3.0 To Be Last Major Releases Under Pivotal Sponsorship". 19 Jan 2015. http://blog.pivotal.io/pivotal/news-2/groovy-2-4-and-grails-3-0-to-be-last-major-releases-under-pivotal-sponsorship ↩
"Groovy joins Apache Incubator". 11 Mar 2015. https://blogs.apache.org/foundation/entry/groovy_submitted_to_become_a ↩
James Strachan (29 Aug 2003). "Groovy - the birth of a new dynamic language for the Java platform". Archived from the original on 1 September 2003. https://web.archive.org/web/20030901064404/http://radio.weblogs.com/0112098/2003/08/29.html ↩
"Java Community Process JSR 241". http://www.jcp.org/en/jsr/detail?id=241 ↩
"Groovy wins first prize at JAX 2007 innovation award". 2007-04-26. Archived from the original on 2015-05-13. Retrieved 2012-10-07. https://web.archive.org/web/20150513184206/http://docs.codehaus.org/display/GROOVY/2007/04/26/Groovy+wins+first+prize+at+JAX+2007+innovation+award ↩
"They say a lot can happen over a cup of coffee". Archived from the original on 2011-04-19. Retrieved 2012-10-07. https://web.archive.org/web/20110419130810/http://jax-award.de/jax_award08/proposal_view_de.php?id=240 ↩
"SpringSource Acquires Groovy and Grails company (G2One)". 11 Nov 2008. http://www.indicthreads.com/2138/springsource-acquires-groovy-and-grails-company-g2one/ ↩
"VMWare Acquires SpringSource". 10 Aug 2009. https://techcrunch.com/2009/08/10/vmware-acquires-springsource/ ↩
"Tweet from James Strachan". November 24, 2016. Retrieved 2016-11-24. https://twitter.com/jstrachan/status/784333918078169088 ↩
"Announcement on dev mailing list". https://mail-archives.apache.org/mod_mbox/groovy-dev/201511.mbox/%3CCAEWfVJ%3DBz-tiTTYHiPc8vY26CopLm3pPy_LADvvFh4vjVs%3Dosw%40mail.gmail.com%3E ↩
"Release GROOVY_3_0_0 · apache/groovy". GitHub. Retrieved 2024-03-27. https://github.com/apache/groovy/releases/tag/GROOVY_3_0_0 ↩
"Release GROOVY_4_0_0 · apache/groovy". GitHub. Retrieved 2024-03-27. https://github.com/apache/groovy/releases/tag/GROOVY_4_0_0 ↩
König 2007, pg. 32 ↩
"Groovy style and language feature guidelines for Java developers". Groovy.codehaus.org. Archived from the original on 2015-01-17. Retrieved 2015-01-22. https://web.archive.org/web/20150117214709/http://groovy.codehaus.org/Groovy+style+and+language+feature+guidelines+for+Java+developers ↩
"Groovy – Differences from Java". Groovy.codehaus.org. Archived from the original on 2009-03-17. Retrieved 2013-08-12. https://web.archive.org/web/20090317025737/http://groovy.codehaus.org/Differences+from+Java ↩
"What's new in Groovy 2.0?". 28 Jun 2012. http://www.infoq.com/articles/new-groovy-20 ↩
König 2007, pp. 37-8 ↩
König 2007, pp. 38-9 ↩
König 2007, pp. 41-3 ↩
"JN3525-MetaClasses". Archived from the original on 2012-10-01. Retrieved 2012-10-07. https://web.archive.org/web/20121001122409/http://groovy.codehaus.org/JN3525-MetaClasses ↩
"Metaprogramming Techniques in Groovy and Grails". 11 Jun 2009. https://www.slideshare.net/zenMonkey/metaprogramming-techniques-in-groovy-and-grails ↩
"Groovy - Closures". Archived from the original on 2012-05-22. https://web.archive.org/web/20120522213410/http://groovy.codehaus.org/Closures ↩
"Does groovy call partial application 'currying'", 10 Aug 2013 http://programmers.stackexchange.com/questions/152868/does-groovy-call-partial-application-currying ↩
"Groovy - Lazy Transformation". Archived from the original on 2012-10-08. Retrieved 2012-10-07. https://web.archive.org/web/20121008091312/http://groovy.codehaus.org/Lazy+transformation ↩
"Side Notes: Lazy lists in Groovy". 3 Feb 2011. http://ndpar.blogspot.com.br/2011/02/lazy-lists-in-groovy.html ↩
"Groovy's Fold". 20 Jun 2011. Archived from the original on 13 February 2015. Retrieved 12 February 2015. https://web.archive.org/web/20150213033355/http://bendoerr.me/posts/2011-06-20-groovy-inject.html ↩
"Functional Programming with Groovy". 5 Nov 2011. https://www.slideshare.net/arturoherrero/functional-programming-with-groovy ↩
"Function programming in Groovy". Archived from the original on 2012-10-08. Retrieved 2012-10-07. https://web.archive.org/web/20121008095622/http://groovy.codehaus.org/Functional+Programming+with+Groovy ↩
"JsonBuilder". Archived from the original on 2012-10-02. Retrieved 2012-10-07. https://web.archive.org/web/20121002221510/http://groovy.codehaus.org/gapi/groovy/json/JsonBuilder.html ↩
"Groovy Strings - Different ways of creating them". 26 Dec 2009. http://rajakannappan.blogspot.com.br/2009/12/groovy-strings-different-ways-of.html ↩
"Compile-time Metaprogramming - AST Transformations". Archived from the original on 2012-10-14. Retrieved 2012-10-07. https://web.archive.org/web/20121014094900/http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations ↩
King, Paul (2020). "A History of the Groovy Programming Language". Proc. ACM Program. Lang. 4: 53. doi:10.1145/3386326. https://doi.org/10.1145%2F3386326 ↩
"ScriptRunner Documentation". https://scriptrunner.adaptavist.com/latest/index.html ↩
"ScriptRunner Press Release with adoption stats". http://www.adaptavist.com/blog/adaptavist-completes-another-acquisition-against-a-backdrop-of-explosive-global-growth/ ↩
"Groovy DSL for OFBiz business logic". Apache OFBiz Project Open Wiki. https://cwiki.apache.org/confluence/display/OFBIZ/Groovy+DSL+for+OFBiz+business+logic ↩
"Simple-methods examples using Groovy". Apache OFBiz Project Open Wiki. https://cwiki.apache.org/confluence/display/OFBIZ/Simple-methods+examples+using+Groovy ↩
"Grails at LinkedIn". Retrieved 2015-06-02. http://blog.linkedin.com/2008/06/11/grails-at-linkedin/ ↩
"Embedded Groovy Scripting". www.logicmonitor.com. Retrieved 2020-11-20. https://www.logicmonitor.com/support/terminology-syntax/scripting-support/embedded-groovy-scripting ↩
"Jenkins Pipeline". https://jenkins.io/doc/book/pipeline/overview/ ↩
Rocher, Graeme (October 2, 2008). "Graeme Rocher's Blog: Sky.com relaunches written in Grails". Graeme Rocher's Blog. Retrieved 2015-06-02. http://graemerocher.blogspot.com.br/2008/10/skycom-relaunches-written-in-grails.html ↩
Security Analysis of Emerging Smart Home Applications https://iotsecurity.eecs.umich.edu/img/Paper27_CameraReady_SmartThings_Revised_IEEEGen.pdf ↩
"Scripting and the Script Library | Scripting & Properties". www.soapui.org. Retrieved 2015-06-02. http://www.soapui.org/Scripting-Properties/scripting-and-the-script-library.html ↩
"Chapter 11. Groovy integration". docs.jboss.org. Retrieved 2015-06-02. http://docs.jboss.org/seam/2.0.2.GA/reference/en-US/html/groovy.html ↩
"vCalc, the First ever Social Platform for the world of Math". 4 November 2014. Retrieved 2016-05-05. http://www.anu.ac.ke/1403/vcalc-the-first-ever-social-platform-for-the-world-of-math/ ↩
"Wired.Com" (PDF). www.springsource.org. Retrieved 2015-06-02. http://www.springsource.org/files/uploads/all/pdf_files/customer/S2_CaseStudy_Wired_USLET_EN.pdf ↩
"XWiki SAS" (PDF). www.springsource.org. Retrieved 2015-06-02. http://www.springsource.org/files/uploads/all/pdf_files/customer/S2_CaseStudy_XWiki.pdf ↩
"Grooscript Documentation". 12 Sep 2016. Archived from the original on 28 June 2017. Retrieved 4 July 2017. https://web.archive.org/web/20170628212516/http://grooscript.org/doc.html ↩
"Presentation at SpringOne/2GX on Grooscript". 13 Dec 2015. https://www.infoq.com/presentations/grooscript ↩
"Grooscript online conversions". 15 May 2017. Archived from the original on 9 July 2017. Retrieved 4 July 2017. https://web.archive.org/web/20170709170154/http://grooscript.org/conversions.html ↩