Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@CompileStatic used on plain Groovy scripts

Tags:

groovy

I'm not sure if this is already possible but is it possible to use @CompileStatic on just plain groovy scripts without wrapping the script in a class?

I'm using the GroovyClassLoader to parse and compile scripts dynamically and so it would be nice if scripts could use @CompileStatic

like image 839
Zocp Avatar asked Jan 24 '26 17:01

Zocp


1 Answers

You can add a compiler customizer:

configuration.addCompilationCustomizers(
    new ASTTransformationCustomizer(CompileStatic))

If you were on the command line you could provide a --configscript config.groovy. This answer has an example of how the script should look like:

withConfig(configuration) {
    ast(groovy.transform.CompileStatic)
}
like image 73
Will Avatar answered Jan 27 '26 00:01

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!