简体   繁体   English

为什么 Eclipse 给我“groovy.lang.GroovyObject 无法解析”?

[英]Why is Eclipse giving me "groovy.lang.GroovyObject cannot be resolved"?

Specs: Linux Mint 18.3, Eclipse 2019-06, Groovy 2.5.8, Java 11规格:Linux Mint 18.3、Eclipse 2019-06、Groovy 2.5.8、Java 11

I started a Groovy project, and created a package "test" under the "source folder".我开始了一个 Groovy 项目,并在“源文件夹”下创建了一个包“test”。 Under test I put a file, "test.groovy".在测试中,我放了一个文件“test.groovy”。 This file looks like this:该文件如下所示:

package test

It's got a horrid white-cross-in-a-red-box.它有一个可怕的红框白十字。 The error message is:错误信息是:

Multiple markers at this line: - The type groovy.lang.MetaClass cannot be resolved.此行有多个标记: - 无法解析 groovy.lang.MetaClass 类型。 It is indirectly referenced from required .class files - The type groovy.lang.GroovyObject cannot be resolved.它是从所需的 .class 文件间接引用的 - 无法解析 groovy.lang.GroovyObject 类型。 It is indirectly referenced from required .class files它是从所需的 .class 文件间接引用的

I have tried multiple strategies: restarting Eclipse, cleaning the project, removing and putting back the JRM for the project.我尝试了多种策略:重新启动 Eclipse、清理项目、删除并放回项目的 JRM。 Nothing doing.无所事事。

There are a few cases of this error when I Google, but mostly they appear to be from years and years ago, on an active bug list, so I presume resolved.当我谷歌时,有几个这个错误的情况,但大多数情况下它们似乎来自多年以前,在一个活跃的错误列表中,所以我认为已经解决。

Any ideas what's going wrong?任何想法出了什么问题?

NB according to my notes, I have had this problem before a couple of times with Gradle projects, and the problem was resolved by going Gradle --> Refresh for the project.注意,根据我的笔记,我之前在 Gradle 项目中遇到过几次这个问题,问题是通过去 Gradle --> 刷新项目来解决的。 But this is a (pure) Groovy project, not Gradle, and the "Refresh" option is not available.但这是一个(纯)Groovy 项目,而不是 Gradle,并且“刷新”选项不可用。

By the way, when I look at this problem in the "Problems" the error type is said to be "Java Problem".顺便说一句,当我在“问题”中查看此问题时,错误类型被称为“Java 问题”。

later之后

It's been suggested that the cause might be Java 11. This is an interesting idea.有人建议原因可能是 Java 11。这是一个有趣的想法。 However, Groovy 2.5.x in itself is not incompatible with Java 11. Firstly, I have no problem running this at the CLI, and no problem with Eclipse-based Gradle projects configured with Java 11 and Groovy 2.5.x, using Groovy as the language of the app and testing files.然而,Groovy 2.5.x 本身并不与 Java 11 不兼容。首先,我在 CLI 上运行它没有问题,并且使用 Java 11 和 Groovy 2.5.x 配置的基于 Eclipse 的 Gradle 项目没有问题,使用 Groovy 作为应用程序和测试文件的语言。 Crucially, of course, the Gradle wrapper chooses its own Groovy version, and in such circs the user chooses their own Groovy version for their executables as a dependency in build.gradle .当然,至关重要的是,Gradle 包装器选择自己的 Groovy 版本,在这种情况下,用户为其可执行文件选择自己的 Groovy 版本作为build.gradle的依赖build.gradle So Eclipse Groovy-handling is mercifully "bypassed".所以 Eclipse Groovy 处理被仁慈地“绕过”了。

I am thus beginning to suspect that the Groovy-Eclipse add-in may be the culprit.因此,我开始怀疑 Groovy-Eclipse 加载项可能是罪魁祸首。 Amazingly enough, and I was surprised by this, I downloaded and set up the 2019-12 Eclipse package, completely separately, and tried to create a Groovy project in it.令人惊讶的是,我对此感到惊讶,我完全独立地下载并设置了 2019-12 Eclipse 包,并尝试在其中创建一个 Groovy 项目。 Even after several attempts to install both the "release" and "snapshot" versions of Groovy-Eclipse for this version of Eclipse (ie here ), I cannot start the simplest of Groovy projects in that IDE.即使在多次尝试为这个版本的 Eclipse(即这里)安装 Groovy-Eclipse 的“发布”和“快照”版本之后,我仍然无法在该 IDE 中启动最简单的 Groovy 项目。

So my suspicions are circling around this theory that Groovy-Eclipse is unable to work properly with Java 11. Only problem is that you might expect to find such a bug as one of the issues , but there is nothing.因此,我怀疑 Groovy-Eclipse 无法与 Java 11 一起正常工作的理论。唯一的问题是您可能希望找到这样的错误作为问题之一,但什么也没有。

Add "requires org.codehaus.groovy;"添加“需要 org.codehaus.groovy;” to your module-info.java到你的 module-info.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM