Grails 4&quot“静态类型检查”仅对日期对象错误

发布于 2025-01-22 12:20:24 字数 1247 浏览 3 评论 0原文

因此,我从Grails 3.3.x迁移到4.0.13。当我尝试编译我的应用程序时,当我尝试使用任何日期属性的格式方法时,我会遇到编译错误。对于Exmaple

class Event {
    Date startDateTime
    Date regDeadline
}

,然后在我的GSON课程中,

model {
    Event event
}

json {
    eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
    regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")
}

我有以下编译错误

Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
raa_domain_grid__event_gson: 10: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 10, column 15.
       eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
                 ^
raa_domain_grid__event_gson: 11: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 11, column 17.
       regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")

,以前没有问题。我怀疑这与Groovy升级到2.5.6有关,但我看不到这个问题是什么。这在我整个应用程序中都在发生。当我尝试将格式应用于它们时,我所有具有日期为属性的课程都会引发此错误。以上只是一个简单的例子。

So I am migrating from Grails 3.3.x to 4.0.13. When I try to compile my app I am getting compilation errors when I try to use the format method for any Date property. For exmaple

class Event {
    Date startDateTime
    Date regDeadline
}

Then in my GSON class I have this

model {
    Event event
}

json {
    eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
    regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")
}

I get the following compiling error

Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
raa_domain_grid__event_gson: 10: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 10, column 15.
       eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
                 ^
raa_domain_grid__event_gson: 11: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 11, column 17.
       regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")

This worked without issues before. I suspect it has something to do with the Groovy upgrade to 2.5.6 but I don't see what that issue would be. This is happening throughout my entire app. All my Classes that have Dates as properties throw this error when I try to apply formatting to them. The above is just a simple example of that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城烟雨 2025-01-29 12:20:24

刚刚发现,在Groovy 2.5中删除了日期助手方法,并将其放入另一个库groovy-dateutil。通过将其添加到我的gradle构建文件中,所有内容都按预期编译。

Just found that the Date helper methods were removed in Groovy 2.5 and put into another library groovy-dateutil. By adding this to my Gradle build file everything compiled as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文