© Adam L. Davis 2016

Adam L. Davis, Learning Groovy, 10.1007/978-1-4842-2117-4_3

3. Tools

Adam L. Davis

(1)New York, USA

In addition to groovy the Groovy installation comes with several helpful tools covered in this chapter.

Console

1   groovyConsole                      

The Groovy Console is a quick and easy way to try things in Groovy visually without the overhead of a complete IDE.

Whenever you have an idea you want to try out quickly, open the Groovy Console, type some code, and then press Ctrl+R to run it. After reading your output and changing the code, press Ctrl+W to clear the output and Ctrl+R again to run the code. Once you get used to those two shortcuts, the Groovy Console might become an indispensable development tool.

It also has the ability (among other things) to inspect the AST (Abstract Syntax Tree ) of your code, the internal representation of the code used by the compiler. Use Script - Inspect Ast or Ctrl+T to open the Groovy AST Browser.

You can provide a classpath to be available at runtime to the Groovy Console using the -cp option. This is useful when you want to refer to other classes you have compiled. For example, in a Linux/OSX environment, you use:

1   groovyConsole -cp src/main/groovy/:src/main/resources/ example.groovy

Compilation

1   groovyc                      

To take advantage of the JDK 7 invoke-dynamic instruction, use the --indy flag1. This also works with the groovy command.

Invoke-dynamic helps the compiler improve the performance of things like duck-typing, meta-programming, and method-missing calls.

Shell

1   groovysh                      

The Groovy shell can be used to execute Groovy code in an interactive command shell.

A426440_1_En_3_Figa_HTML.jpg Exercise

Try it out!

Documentation

1   groovydoc                      

This tool generates documentation from your Groovy code.

Groovy uses the same comment syntax as Java, including the conventions for documenting code.

1   /** This is a documentation comment. */          
1   /* This is not */
1   // This is a one-line comment.

Footnotes

1 Available in Groovy 2.0 and above.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.157.142