Martini Services Groovy Class Compilation
In Martini's development environment, Groovy classes and scripts are compiled with a specific compiler configuration. This setup not only includes standard configurations like source encoding and classpath but also extends to more advanced operations such as applying AST transformations and managing global settings.
Martini uses a default compilation customizer (located at <martini-home>/conf/MartiniGroovyCompilerConfig.groovy
) to automatically apply several modifications during the compilation of your Groovy classes and scripts:
Default Compiler Customizations
Martini's compiler configuration includes:
- Automatic import of frequently used packages, such as:
io.toro.martini.core.service.annotation.*
io.toro.martini.core.api.*
groovyx.net.http.*
- Groovydoc or Javadoc parsing, with an implicit addition of the
@Documented
annotation, facilitating Swagger API definitions generation.
Consider this example Groovy class:
1 |
|
Post-compilation in Martini, the class would resemble:
1 |
|
These enhancements aim to reduce boilerplate code, enabling you to write more efficient and less verbose scripts.
Customizing the Compilation Process
To tailor the compilation process to your specific needs, modify the MartiniGroovyCompilerConfig.groovy
file. This file informs the Groovy compiler about your custom configurations through the configscript
flag1.
For instance, to add implicit imports across all your Groovy files:
1 |
|
For detailed guidance on compilation customization, refer to the official Groovy documentation and external resources like Groovy Goodness blog post.
Restart Requirement
After modifying MartiniGroovyCompilerConfig.groovy
, restarting your Martini instance is advisable to ensure the changes take effect.
-
Note: The file name and location for the Groovy compiler configuration script are determined by Martini's internal implementation. ↩