groovy - @CompileStatic 用于普通 Groovy 脚本

标签 groovy

我不确定这是否已经可行,但是否可以在普通的 groovy 脚本上使用 @CompileStatic 而无需将脚本包装在类中?

我正在使用 GroovyClassLoader 来动态解析和编译脚本,所以如果脚本可以使用 @CompileStatic 就好了

最佳答案

您可以添加 compiler customizer :

configuration.addCompilationCustomizers(
    new ASTTransformationCustomizer(CompileStatic))

如果您在命令行上,您可以提供一个--configscript config.groovyThis answer有一个脚本应该是什么样子的例子:

withConfig(configuration) {
    ast(groovy.transform.CompileStatic)
}

关于groovy - @CompileStatic 用于普通 Groovy 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38619250/

相关文章:

xml - 在 XmlSlurper 的 GPath 中使用变量

groovy - 使用Jenkins http-request-plugin进行基本身份验证

grails - 将参数从一种方法传递到 Controller 中的另一种方法

java - 在两个标签之间以常规方式解析?

java - 如何使用 java 或 groovy 计算目录上的 md5 校验和?

groovy - 仅测试 if 语句中变量不为 null

groovy - groovy中 "<<"(双小于)的目的是什么

grails - 用枚举类型查询时,GRAILS GORM显示错误结果

grails - Grails模板中可用的变量

spring - ref() 没有在 grails 上使用 spring dsl 获取嵌套映射值的 bean 配置