Groovy provides many metaprogramming hooks for changing the runtime behavior of classes and objects. In addition, it provides hooks into Groovy's compilation process so that you can make changes to the language at compile time. These hooks are done through a mechanism called AST Transformations (sometimes refered to as macros in other languages).
The hook for accessing this capability is via annotations. In your Groovy code you will make use of one of more annotations. Behind the scenes, an AST processor relevant to the annotation you are using is inserted into the compiler phases at the appropriate point. You can explore some of the more popular Annotations below:
Grape also provides its own transformation with @Grab.
Implementing your own AST Transformations
There are two kinds of AST Transformations: local and global transformations: