【问题标题】:Grails 4: @GrailsCompileStatic annotation not workingGrails 4:@GrailsCompileStatic 注释不起作用
【发布时间】:2019-03-28 07:15:10
【问题描述】:

从 grails 3.3.5 迁移 -> grails 4.0.0.M2

我的课程已经用@GrailsCompileStatic 进行了注释,并且它过去在 3.3.5 中编译时没有任何问题。

许多其他类也显示由 groovy 额外提供的方法的错误,例如 Date.parse()Date.format()Date.minus()

错误:

FileCommandReader.groovy: 163: [Static type checking] - Cannot find matching method java.util.Date#parse(java.lang.String, java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 163, column 17.
                Date expiry = Date.parse("HH:mm:ss", cols[2]);

【问题讨论】:

    标签: grails grails-4


    【解决方案1】:

    这不是真正的@GrailsCompileStatic 问题。 Grails 4.0 使用 Groovy 2.5.6。以下代码无法使用 Groovy 2.5.6 编译...

    import groovy.transform.CompileStatic
    
    @CompileStatic
    class Helper {
    
        void someMethod() {
            Date.parse '', ''
        }
    }
    

    Grails 3.3.5 使用 Groovy 2.4.15,上面的代码在 Groovy 2.4.15 中有效。

    【讨论】:

    • groovy-dateutil 方法是 Groovy 2.5 中的一个可选模块,为现在推荐的 groovy-datetime 模块(java.time 包)让路。如果要使用这些扩展方法,则需要添加额外的 groovy-dateutil 依赖项。
    • 感谢@PaulKing 将使用其他选项。
    猜你喜欢
    • 2018-02-22
    • 2014-08-14
    • 1970-01-01
    • 2017-08-08
    • 2013-01-12
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 2013-09-20
    相关资源
    最近更新 更多