Skip to end of metadata
Go to start of metadata

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

Learn all about the Groovy Ecosystem at GR8Conf

If you're interested in all those great technologies of the Groovy ecosystem, including Grails, Gradle, Griffon, Spock, Gaelyk, and more, be sure to join the Groovy fans at the GR8Conf conference which takes place in Copenhagen, Denmark, on June 6th - 8th. GR8Conf is an affordable conference dedicated to that ecosystem, where you'll learn about the latest novelties and development of those Groovy-powered technologies by the makers themselves, and where you'll have a chance to network with the Groovy users out there.

Experience Groovy 1.8

Groovy 1.8 is the latest major and stable version of the popular dynamic language for the JVM. To learn more about the novelties, make sure to read the release notes. In a nutshell, Groovy 1.8 provides new Domain-Specific Language authoring capabilities for more readability and expressivity of your business rules, runtime performance improvements, the bundling of the GPars parallel and concurrency library, built-in JSON support, new compile-time meta-programming features (several new useful AST transformations), new functional programming aspects for closures, and much more.


"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

Latest news [more]

The Groovy development team is pleased to announce the release of the last beta version in the 2.0.0 release cycle!

This version introduces two major enhancements: the @CompileStatic annotation (which enables static compilation of Groovy code) and support for invokedynamic (known as indy)!

If you already gave a try to the static type checker available in previous beta releases of Groovy 2.0, static compilation is a step further. Basically, replacing the @TypeChecked annotation with @CompileStatic, your code will be statically compiled.

Support for the new "invokedynamic" JVM instructions is also bundled into this distribution. However, as we must maintain binary compatibility with previous versions of Groovy and JDKs (especially, support for JDK 5 and 6), the indy-enabled version of Groovy is available in a separate jar. If you use Maven, Ivy or Gradle, the jar is available using the "indy" classifier. If you use the distribution zip, you will find two jars in a separate directory ("indy"), corresponding to groovy.jar and groovy-all.jar (for embedded version).

We strongly encourage you to test both static compilation (and type checking) and invoke dynamic support because this release is the last beta: the next Groovy version will be an RC with modularisation included. More than ever, we need beta testers!

You can download Groovy 2.0.0-beta-3 at the regular place: http://docs.codehaus.org/display/GROOVY/Download

For those who are interested in bug fixes since beta 2, you can read the release notes: http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10242&version=18244

Thanks to all our contributors and all your feedback!

  1. Apr 23, 2008

    Hi,

    I am unable to get the example that you have posted on InfoQ for using the tripple dot notation of variable args list. i.e I cut and pasted the following code

    into groovyconsole and I get the following:

    Exception thrown: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script14: 1: unexpected token: ... @ line 1, column 21.
    1 error
    
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script14: 1: unexpected token: ... @ line 1, column 21.
    1 error
    

    Am I missing something?

    Thanks

    Vimal 

  2. Apr 23, 2008

    Vimal,

    I tried it, but now i get another error:

    groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.size() is applicable for argument types: () values: {}
    	at Script14.sum(Script14:3)
    	at Script14.run(Script14:8)
    
  3. Apr 23, 2008

    Vimal, try this:

  4. Oct 13, 2008

    Oh,in Groovy1.6.0b2,  following line CAN'T run:

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

    Caught: groovy.lang.MissingPropertyException: No such property: args for class: script_from_command_line
    at script_from_command_line.run(script_from_command_line:1)

    It's just on groovy's HOMEPAGE !

  5. Oct 14, 2008

    James, this is a known problem, and a JIRA issue was raised.

    This regression will be fixed for Groovy 1.6-rc-1.

    Sorry for the inconvenience.

  6. Oct 31, 2008

    Thanks glaforge.  I've fixed my Groovy 1.6b2 with your method. Open source is great!

  7. Apr 08, 2009

    What about shortening the names for things in Groovy? like Maven has the mvn command.

     E.g.

    groovy => gv

    groovyc => gvc

    groovysh => gvsh

    groovlet script => gvp (isn't it sort of  jsp like stuff?)

    ... 

    (then rewrite the old ones to call the new-names for backward compatibility)

  8. Sep 24, 2009


    (9/24/2009 - fixed blog so that the linked entry displays properly in web browser)

    There are times when we need to read a single record at a time from a file.
    Eg., if we want to stop reading a file at a certain point.
    Or when working with more than one file. After comparing records, one might have to read a record from one or the other file, or from both.

    I was not able to find good documentation on how to do this.
    By spending a lot of time searching and experimenting, I was able to find out how to do it.

     see http://patriciashannon.blogspot.com/2009/09/groovy-how-to-read-one-line-at-time.html

     Note that it requires two executions of .readLine for each record, but that is easy to get around, but putting it in a closure, as shown. This would usually be done anyway, to include things like record counts and end-of-file logic. So in a real program, each readALine closure would have two readLine statements.

  9. Sep 26, 2009

    When I put the following in my initialization routine, highValue was undefined elsewhere
         String highValue = '\377'

    So I changed the code to the following two lines, which worked
         String highValue2 = '\377'
         highValue = highValue2

    When I replaced these two lines by the following, it was again undefined elsewhere
         public String highValue = '\377'

    Is there a way to define a global typed variable with a single statement?