What Groovy Can Do For You, Page 4
Groovy IDE and editor support
If you plan to code in Groovy often, you should look for Groovy support for your IDE or editor of choice. Some editors only support syntax highlighting for Groovy at this stage, but even that can be useful and can make Groovy code more convenient to work with. Some commonly used IDEs and text editors for Groovy are listed in the following sections.
This section is likely to be out of date as soon as it is printed. Stay tuned for updates for your favorite IDE, because improved support for Groovy in the major Java IDEs is expected in the near future. Sun Microsystems recently announced Groovy support for its NetBeans coyote project (https://coyote.dev.java.net/), which is particularly interesting because it is the first IDE support for Groovy that is managed by the IDE's own vendor itself.
IntelliJ IDEA plug-in
Within the Groovy community, work is ongoing to develop an open-source plugin called GroovyJ. With the help of this plug-in and IDEA's built-in features, a Groovy programmer can benefit from the following:
- Simple syntax highlighting based on user preferences: GroovyJ currently uses Java 5's syntax highlighter, which covers a large proportion of the Groovy syntax. Version 1.0 will recognize the full Groovy syntax and allow customization of the highlighting through the Colors & Fonts panel, just as it is possible with the Java syntax.
- Code completion: To date, code completion is limited to word completion, leveraging IDEA's word completion based on an on-the-fly dictionary for the current editor only.
- Tight integration with IDEA's compile, run, build, and make configuration as well as output views.
- Lots of advanced editor actions that can be used as in Java.
- Efficient lookup for all related Java classes in the project or dependent libraries.
- Efficient navigation between files, including .groovy files.
- A Groovy file-type icon.
GroovyJ has a promising future, which is greatly dependent on its implementation of IDEA's Program Structure Interface (PSI) for the Groovy language. It will do so by specializing the Groovy grammar file and generating a specialized parser for this purpose. Because IDEA bases all its advanced features (such as refactoring support, inspections, navigation, intentions, and so forth) on the PSI, it seems to be only a matter of time before we will see these features for Groovy.
GroovyJ is an interesting project, mindfully led by Franck Rasolo. This plug-in is one of the most advanced ones available to Groovy at this point. For more information, see http://groovy.codehaus.org/GroovyJ+Status.
The Groovy plug-in for Eclipse requires Eclipse 3.1.1 or newer. The plug-in will also run in Eclipse 3.x-derived tools such as IBM Rational's Rational Application Developer and Rational Software Architect. As of this writing, the Groovy Eclipse plug-in supports the following features:
- Syntax highlighting for Groovy files
- A Groovy file decorator (icon) for Groovy files in the Package Explorer and Resources views
- Running Groovy scripts from within the IDE
- Auto-build of Groovy files
- Debugger integration
The Groovy Eclipse plug-in is available for download at http://groovy.codehaus.org/ Eclipse+Plugin.
Groovy support in other editors
Although they don't claim to be full-featured development environments, a lot of all-purpose editors provide support for programming languages in general and Groovy in particular.
UltraEdit can easily be customized to provide syntax highlighting for Groovy and to start or compile scripts from within the editor. Any output goes to an integrated output window. A small sidebar lets you jump to class and method declarations in the file. It supports smart indentation and brace matching for Groovy. Besides the Groovy support, it is a feature-rich, quick-starting, all-purpose editor. Find more details at http://groovy.codehaus.org/UltraEdit+Plugin.
The JEdit plug-in for Groovy supports executing Groovy scripts and code snippets from within the editor. A syntax-highlighting configuration is available separately. More details are available here: http://groovy.codehaus.org/JEdit+Plugin. Syntax highlighting configuration files for TextPad, Emacs, Vim, and several other text editors can be found on the Groovy web site at http://groovy.codehaus.org/Other+Plugins.
When programming small ad-hoc Groovy scripts, I (Dierk) personally use
UltraEdit on Windows and Vim on Linux. For any project of some size, I
use IntelliJ IDEA with the GroovyJ plug-in.
As Groovy matures and is adopted among Java programmers, it will continue to gain support in Java IDEs with features such as debugging, unit testing, and dynamic code-completion.
We hope that by now we've convinced you that you really want Groovy in your life. As a modern language built on the solid foundation of Java and with support from Sun, Groovy has something to offer for everyone, in whatever way they interact with the Java platform.
With a clear idea of why Groovy was developed and what drives its design, you should have been able to see where features fit into the bigger picture. Keep in mind the principles of Java integration and feature richness, making common tasks simpler and your code more expressive.
Once you have Groovy installed, you can run it both directly as a script and after compilation into classes. If you have been feeling energetic, you may even have installed a Groovy plug-in for your favorite IDE. With this preparatory work complete, you are ready to see (and try!) more of the language itself.
- ¹ Every ordinal number N can be uniquely disassembled into factors that are prime numbers: N = p1*p2*p3. The disassembly problem is known to be "hard." Its complexity guards cryptographic algorithms like the popular Rivest-Shamir-Adleman (RSA) algorithm.
- ² Leonardo Pisano (1170..1250), aka Fibonacci, was a mathematician from Pisa (now a town in Italy). He introduced this number sequence to describe the growth of an isolated rabbit population. Although this may be questionable from a biological point of view, his number sequence plays a role in many different areas of science and art. For more information, you can subscribe to the Fibonacci Quarterly.
- ³ The command line as shown applies to Windows shells. The equivalent on Linux/Solaris/UNIX/Cygwin would be java -cp $GROOVY_HOME/embeddable/groovy-all-1.0.jar:classes Fibonacci
- &sup4; Groovy ships with its own copy of the Ant jar files that could also be used for this purpose, but it is easier to explain with a standalone installation of Ant.
About the Authors
Dierk Koenig is a senior software developer, mentor and coach. He publishes in leading German magazines on software development and speaks at international conferences. He works at Canoo Engineering AG, Basel, Switzerland, where he is the founding partner and member of the executive board. He joined the Groovy project in 2004 working as a committer ever since.
Andrew Glover is the President of Stelligent Incorporated which helps companies address software quality with effective developer testing strategies and continuous integration techniques that enable teams to monitor code quality early and often. He actively blogs about software quality at thediscoblog.com and testearly.com.
Dr Paul King is Managing Director and Principal Consultant for ASERT, an Australian company specialising in helping its customers leverage emerging technologies. He has provided technical and strategic consulting to hundreds of organizations throughout the U.S. and Asia Pacific and is an active contributor to many open source projects. When not being a taxi service for his seven children, you will find Paul tinkering with the latest Agile or enterprise technologies.
As the official Groovy Project Manager and member of the JSR-241 Expert Group standardizing the Groovy Scripting Language, Guillaume Laforge is a passionate Groovy developer. In his professional career, Guillaume is a software architect and Open Source consultant, working for OCTO Technology, a company focusing on architecture of software and information systems
Jon Skeet is a software engineer and inveterate technological dabbler who happens to specialise in Java and C# development. A recent convert to Groovy, Jon is fanatical about using smarter ways to write cleaner, more readable code.
Source of This MaterialGroovy in Action
By Dierk Koenig with Andrew Glover, Paul King, Guillaume Laforge & Jon Skeet
Published: January, 2007, Paperback: 696 pages
Published by Manning Publications
Retail price: $44.99 for the Softbound print book + PDF ebook or $25.00 for the PDF ebook both through www.manning.com.
This material is from Chapter 1 of the book.