This manual is a work in progress and is currently incomplete.
If you'd like to help improve it, and we hope you do, please see the README.

10 Groovy

Groovy is an alternative JVM programming language. It has a strong synergy with Java and many language and library features that make it a compelling programming environment. Ratpack provides strong integration with Groovy via the ratpack-groovy and ratpack-groovy-test libraries. Writing Ratpack applications in Groovy generally leads to less code through Groovy’s concise syntax compared to Java and a more productive and enjoyable development experience. To be clear though, Ratpack applications do not need to be written in Groovy.

Groovy is commonly known as a dynamic language. However, Groovy 2.0 added full static typing and static compilation as an option. Ratpack’s Groovy support is strictly designed to fully support “static Groovy” and also leverages the newest features of Groovy to avoid introducing boilerplate code to achieve this goal. Said another way, Ratpack’s Groovy support does not use any dynamic language features and has a strongly typed API.

TODO: find decent links describing static Groovy and use above

10.1 Prerequisites

If you are new to Groovy, you may want to research the following foundational Groovy topics before proceeding:

  1. Closures
  2. The def keyword

TODO: what else should be in this list? Also, links needed

something else

10.2 Ratpack Groovy API

TODO: explain that Groovy API wraps Java API and mirrors it in corresponding ratpack.groovy.*

10.2.1 @DelegatesTo

TODO: explain this Groovy feature and outline Ratpack’s extensive use of it

10.3 GroovyRatpackMain

The ratpack-groovy library provides the GroovyRatpackMain application entry point that bootstraps the Groovy support. This extends from RatpackMain, but forces the handler factory to be an instance of GroovyScriptFileHandlerFactory.

10.4 ratpack.groovy script

TODO: introduce DSL used in this file, discuss reloading when in reloadable mode

10.5 handlers {} DSL

TODO: introduce the GroovyChain DSL, and closures as handlers

10.6 GroovyChainAction

TODO: Point out the existence of GroovyChainAction

10.7 Testing

TODO: Discuss Groovy testing specifics (might move some content from the testing chapter)