Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

Home Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Groovy...

  • is an agile and dynamic language for the Java Virtual Machine
  • builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
  • makes modern programming features available to Java developers with almost-zero learning curve
  • supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
  • makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
  • increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
  • simplifies testing by supporting unit testing and mocking out-of-the-box
  • seamlessly integrates with all existing Java classes and libraries
  • compiles straight to Java bytecode so you can use it anywhere you can use Java

Experience the latest Groovy 1.7

Groovy 1.7, the latest major and stable version of the popular dynamic language for the JVM, has been released. To learn more about the novelties, make sure to read the release notes. In a nutshell, Groovy 1.7 provides support for Anonymous Inner Classes and Nested Classes, annotations, SQL, Groovy console and Grape enhancements, the nicer Power Assert assertion, an AST Viewer and an AST Builder, a fully rewritten GroovyScriptEngine, and much more!

Dedicated conference: SpringOne2GX 2010

SpringSource in conjunction with the No Fluff Just Stuff Symposium Series are pleased to present SpringOne 2GX, the premier Java event of 2010. SpringOne 2GX is a collocated event covering the entire Spring ecosystem and Groovy/ Grails technologies.

SpringOne 2GX is a one-of-a-kind conference for application developers, solution architects, web operations and IT teams who develop, deploy and manage business applications. This is the most important Java event of 2010, especially for anyone using Spring technologies, Groovy & Grails, or Tomcat. Whether you're building and running mission-critical business applications or designing the next killer cloud application, SpringOne 2GX will keep you up to date with the latest enterprise technology.

Featuring over eighty presentations delivered by development leads and published authors on the Spring, Groovy/ Grails, Tomcat and Cloud technology today, it's the ideal place to obtain critical skills to help you build, run and manage tomorrow's software solutions. Plus you'll meet and learn from open source leaders who drive innovation for these technologies.

This year's event will be held at the newly restored JW Marriott Chicago. Soaring among skyscrapers in the heart of one of the world's most powerful financial districts, the luxurious JW Marriott Chicago was originally designed by renowned architect Daniel Burnham, an urban planner who created the modern city plan for Chicago.

Groovy, an award-winning creative and innovative project

  JAX is the most important Java conference in Germany. Every year, the organizers are running a contest to select the most innovative and creative projects. From over 40 proposals, the jury selected only ten nominees. Although great projects were selected, like the Matisse GUI builder in NetBeans, or the Nuxeo Enterprise Content Management solution, Groovy won the first prize! It is a great honor and a huge pleasure for us to receive such a prize, especially knowing the cool projects we were competing with, or the past winners like the Spring framework.

Dierk König, author of the best-selling " Groovy in Action" book, received the prize in the name of the Groovy community, after having presented several sessions on Groovy at this conference. This award proves and reaffirms how innovative, creative and influential the Groovy project is for the Java community.





"Groovy is like a super version of Java. It can leverage Java's enterprise capabilities but also has cool productivity features like closures, builders and dynamic typing. If you are a developer, tester or script guru, you have to love Groovy."



















Samples

A simple hello world script:

def name='World'; println 
"Hello $name!"
          





A more sophisticated version using Object Orientation:

class Greet {
  def name
  Greet(who) { name = who[0].toUpperCase() +
                      who[1..-1] }
  def salute() { println 
"Hello $name!" }
}

g = 
new Greet('world')  
// create object
g.salute()              
// Output 
"Hello World!"
          





Leveraging existing Java libraries:

import 
static
org.apache.commons.lang.WordUtils.*

class Greeter 
extends Greet {
  Greeter(who) { name = capitalize(who) }
}

new Greeter('world').salute()
          





On the command line:

groovy -e 
"println 'Hello ' + args[0]" World
          









Documentation [more]

Getting Started Guide

How to install and begin using Groovy as well as introductory tutorials.

User Guide

Provides information about using the Groovy language including language facilities, libraries and programming guidelines.

Cookbook Examples

Illustrates larger examples of using Groovy in the Wild with a focus on applications or tasks rather than just showing off the features, APIs or modules.

Developer Guide

Contains information mainly of interest to the developers involved in creating Groovy and its supporting modules and tools.

Testing Guide

Contains information of relevance to those writing developer tests or systems and acceptance tests.

Advanced Usage Guide

Covers topics which you don't need to worry about initially when using Groovy but may want to dive into to as you strive for Guru status.

Modules [more]



The following modules and contributions are currently available:

  • COM Scriptingscript Windows ActiveX and COM components with Groovy
  • Gant
  • GFreeMarkeran integration of the FreeMarker template engine for Groovy
  • Google Data Supportmakes using the Google Data APIs easier from within Groovy
  • Grama simple xdoclet-like tool for processing doclet tags or Java 5 annotations
  • GraphicsBuilderGraphicsBuilder is a Groovy builder for Java 2D
  • Grapplet
  • GriffonDekstop Enhancements for Groovy
  • GrooshProvides a shell-like capability for handling external processes.
  • Groovy Jabber-RPCallows you to make XML-RPC calls using the Jabber protocol
  • GroovyJMS
  • GroovyLabProvides a domain specific language (DSL) for math engineering (matlab-like syntax).
  • Groovy Monkeyis a dynamic scripting tool for the Eclipse Platform
  • GroovyRestletGroovy DSL for constructing Restlet application
  • Groovy Science
  • Groovy SOAPcreate a SOAP server and make calls to remote SOAP servers using Groovy
  • GroovySWTa wrapper around SWT, the eclipse Standard Widget Toolkit
  • GroovyWSGroovySOAP replacement that uses CXF and Java5 features
  • GSPmeans GroovyServer Pages, which is similar to JSP (JavaServer Pages)
  • GSQLsupports easier access to databases using Groovy
  • HTTP Builderprovides a convenient builder API for complex HTTP requests
  • JideBuilderJideBuilder is a Groovy builder for the open source JIDE Common Layer
  • MetaBuilderMetaBuilder is a builder that builds builders.
  • Native Launchera native program for launching groovy scripts
  • Proxy-o-MaticProxy-o-Matic lets you create dynamic proxies fast and in an homogeneous way
  • Windows NSIS-Installera Windows-specific installer for Groovy
  • Windows Servicesframework for Groovy-based WinNT (Windows) Services
  • WingSBuilderWingsBuilder is a Groovy builder for the wingS Framework
  • XMLRPCallows you to create a local XML-RPC server and/or to make calls on remote XML-RPC servers
  • GaelykGaelyk is a lightweight Groovy toolkit for developing and deploying Groovy applications on Google App Engine.
  • GMaven
  • Groovy TransformsProvides additional AST Transformations
  • Grails — a Groovy-based web framework inspired by Ruby on Rails
  • GORM — the Grails Object-Relational Mapping persistence framework
  • Griffon — a Groovy-based desktop framework inspired by Grails
  • GroovyPlugin — A Groovy plugin for JSPWiki
  • OCM Groovy — A Object Content Mapping implemented in Groovy leveraging the Java Content Repository (JCR)
  • Tellurium — A test framework built on top of the Selenium test framework implemented in Groovy
  • Gradle — The next generation build system
  • GPars — A Groovy concurrency/parallelism library


Enjoy making your code groovier !!!!







Latest news

If you wish to stay up-to-date with our vibrant community, you can learn more about:

And below, you will find the latest announcements:

Windows-Installer for Groovy 1.7.4 released

The Windows-Installer for Groovy 1.7.4 can now be downloaded from the Groovy Website ( direct link). It takes care of the gory details of a Windows installation, copying files, setting environment variables and file associations.

It contains the Groovy 1.7.4 Binaries, API Docs and a PDF snapshot of the Wiki, the native launcher, easyb 0.9.7, Gaelyk 0.4, Gant 1.9.3, GMock 0.8.0, GPars 0.10, Griffon Builders (0.3.0 compatible), GroovyServ 0.3, Scriptom 1.6.0, Spock 0.4. The installation of everything but the binaries including the native launcher is optional.

Currently supported languages for the installer are english, german, spanish, french and brazilian portuguese.

Groovy 1.7.4 and the fist beta drop of Groovy 1.8

This is with great pleasure that the Groovy development team is happy to announce the joint releases of Groovy 1.7.4 and Groovy 1.8-beta-1!

Groovy 1.7.4

Groovy 1.7 is our official stable branch, and 1.7.4 is a new minor release of that breed.

Among other things, we fixed a few issues with automatic reloading when using the GroovyScriptEngine, with the joint compiler, with some minor syntax issues with Enums. We added a few new GDK methods like File.renameTo(String path), minus and intersect for sets, etc. And we have new option in the Groovy swing console to compile scripts -- versus running them right away.

You can have further details on Groovy 1.7.4 in the JIRA release notes.

Groovy 1.8-beta-1

Groovy 1.8-beta-1 is the first drop of what the next major version of Groovy will be -- we plan on releasing 1.8-final at the end of the year.

From a practical Groovy developer perspective, we've decided to move to Gradle for our build, thanks to the help of Hans Dokter. This release was still done with Ant, but our final build should be ready soon for prime-time, and we're also seizing this opportunity to work in parallel on making Groovy more modular. Some early work towards more granular Groovy JAR(s) have already started on modules for JMX and BSF, as first experiments.

In this first beta, we obviously included all the bug fixes and minor enhancements from the 1.7 branch. And we've been working on new features as well:

  • closures are now "callable" (inheriting from java.util.concurrent.Callable)
  • new AST transformations like
    • @Log to inject a logger in your classes
    • @ScriptField for creating a field in a script (should be renamed to @Field in the next beta)
    • @PackageScope now working also on methods and classes (not just fields as before)
    • @Synchronized for providing safer synchronization semantics
    • @InheritConstructors to inherit constructors, like often the case when extending exception classes
    • @IndexedProperties to add JavaBeans indexed property support
    • @AutoClone providing automatic cloning support to your beans
    • @AutoExternalize providing automatic externalization of your POGOs
    • @Canonical adding proper equals(), hashCode(), toString() methods
    • @EqualsAndHashCode adding an equals() and hashCode() method
    • @ToString for creating a default readable toString() method
    • @TupleConstructor for adding a tuple constructor
  • an additional syntax for strings, with $/.../$, to circumvent various escaping corner cases, like for example $/a/b\c$$ $//$
  • new GDK methods like Map.countBy{}, Map.collectEntries{}, Date.putAt() (subscript operator), Date.updated()
  • + obviously all other incremental improvements and new features from the Groovy 1.7 branch like
    • the new String methods like tr(), stripMargin(), stripIndent(), (un)expand(), 
    • Map's withDefault{} method, 
    • Closure's ncury() and rcury()
    • Sql's withBatch{} and withTransaction{}A feature I'd also like to highlight in particular is "closure annotation parameters". In Java, there's a limited set of types you can use as annotation parameters (String, primitives, annotations, classes, and arrays of these). But in Groovy 1.8, we're going further and let you use closures as annotation parameters – which are actually transformed into a class parameter for compatibility reasons.
import java.lang.annotation.\*

@Retention(RetentionPolicy.RUNTIME)
@
interface Invariant {
    
Class value() 
// will hold a closure class
}

@Invariant({ number >= 0 })
class Distance {
    
float number
    
String unit
}

def d = 
new Distance(number: 10, unit: 
"meters")

def anno = Distance.getAnnotation(Invariant)
def check = anno.value().newInstance(d, d)

assert check(d)
    

Closure annotation parameters open up some interesting possibilities for framework authors!

You can have a look at the JIRA release notes for Groovy 1.8-beta-1.

You can download Groovy 1.7.4 and Groovy 1.8-beta-1 in the download section of the Groovy website.

Thanks a lot to everybody for their contributions and involvement in those two new milestones!