Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomprehensible problem - groovy.lang.GroovyObject cannot be resolved #1045

Closed
Mrodent opened this issue Feb 28, 2020 · 18 comments
Closed

Incomprehensible problem - groovy.lang.GroovyObject cannot be resolved #1045

Mrodent opened this issue Feb 28, 2020 · 18 comments

Comments

@Mrodent
Copy link

Mrodent commented Feb 28, 2020

Is GroovyEclipse meant to work with Java 11?
Specs: Linux Mint 18.3, Eclipse 2019-06, Groovy 2.5.8, Java 11

I am unable to use GroovyEclipse in either Eclipse 2019-06 or Eclipse 2019-12. I have all sorts of issues and complaints when trying to install, and when I try to start a Groovy project and create the simplest possible Groovy file, I get “groovy.lang.GroovyObject cannot be resolved”.

Eclipse has been one of my most implacable foes for many years. I have tried many strategems to get this to work. Installing a fresh version of 2019-12 just produces the same error out of the box.

At the same time I have no problem with Eclipse Gradle projects, or running Groovy at the CLI. More details here.

@Mrodent Mrodent changed the title Incomprehensible problem Incomprehensible problem - groovy.lang.GroovyObject cannot be resolved Feb 28, 2020
@eric-milles
Copy link
Member

eric-milles commented Feb 28, 2020

Thanks for reaching out for support. I'm glad to have a chance to ask questions and get this resolved. Stackoverflow is tough to have dialog/conversation.

Yes indeed, Eclipse and the Groovy Development Tools (GDT) support Java 11. I have tried out Java 9, 10, 11, 12 and 13 to ensure support. There are a couple things I can say up front.

  1. I would recommend running eclipse with a Java that is equal to or greater than the java you want to use for your project. So in your case, run eclipse with Java 11 and set your project to Java 11 compliance.

  2. It sounds like your eclipse installation is the problem, not your project setup. GDT patches the JDT so that Groovy and Java can co-exist in the same project even in the same package. This patch is version aligned with your eclipse install. So if you are using Eclipse 2019-12, then you should be using the GDT update site https://dist.springsource.org/snapshot/GRECLIPSE/e4.14 (or the release site for more stability). You mentioned at install time that it recommended changing a bunch of plug-ins; this is a sign that the patch version is not aligned with the JDT version you have.

@Mrodent
Copy link
Author

Mrodent commented Feb 29, 2020

Thanks very much. Will try again with 2019-12...

@eric-milles
Copy link
Member

Thanks for the update. Let me know if you run into any problems. If you can capture a screenshot, that may help me understand where you ran into issues.

@Mrodent
Copy link
Author

Mrodent commented Feb 29, 2020

So I try again: fresh placing of the extracted Eclipse 2019-12 files under /opt/eclipse

  • I run it and choose a new workspace
  • I check that Eclipse 2019-12 is using Java 11: yes... installed JRE, compliance level, etc.: all say "java-11-openjdk-amd64", etc.
  • I try to install with Install new software --> Add repository --> Location https://dist.springsource.org/snapshot/GRECLIPSE/e4.15
  • I check "Main Package" only
  • I immediately get "cannot do it, computing alternatives..." then quickly get a message:

Cannot complete the install because one or more required items could not be found.
Software being installed: Eclipse Groovy Development Tools 3.7.0.v202002272322-e2003 (org.codehaus.groovy.eclipse.feature.feature.group 3.7.0.v202002272322-e2003)
Missing requirement: Eclipse JDT Core patch for Groovy 3.7.0.v202002272322-e2003 (org.codehaus.groovy.jdt.patch.feature.group 3.7.0.v202002272322-e2003) requires 'org.eclipse.equinox.p2.iu; org.eclipse.jdt.feature.group [3.18.300.v20200219-1800,3.18.300.v20200219-1800]' but it could not be found
Cannot satisfy dependency:
From: Groovy-Eclipse Compilerless feature 3.7.0.v202002272322-e2003 (org.codehaus.groovy.compilerless.feature.feature.group 3.7.0.v202002272322-e2003)
To: org.eclipse.equinox.p2.iu; org.codehaus.groovy.headless.feature.feature.group [3.7.0.v202002272322-e2003,3.7.0.v202002272322-e2003]
Cannot satisfy dependency:
From: Eclipse Groovy Development Tools 3.7.0.v202002272322-e2003 (org.codehaus.groovy.eclipse.feature.feature.group 3.7.0.v202002272322-e2003)
To: org.eclipse.equinox.p2.iu; org.codehaus.groovy.compilerless.feature.feature.group [3.7.0.v202002272322-e2003,3.7.0.v202002272322-e2003]
Cannot satisfy dependency:
From: Groovy-Eclipse Headless feature 3.7.0.v202002272322-e2003 (org.codehaus.groovy.headless.feature.feature.group 3.7.0.v202002272322-e2003)
To: org.eclipse.equinox.p2.iu; org.codehaus.groovy.jdt.patch.feature.group [3.7.0.v202002272322-e

@eric-milles
Copy link
Member

eric-milles commented Feb 29, 2020

Sorry, my fault. Eclipse 2019-12 is 4.14. https://dist.springsource.org/snapshot/GRECLIPSE/e4.14

You can double-check because the feature and plug-ins end with "e2003" and not "e1912" in the messages above.

@Mrodent
Copy link
Author

Mrodent commented Feb 29, 2020

Thanks, yes, I did install the right version yesterday in fact. I tried both the correct snapshot and the correct release versions for 2019-12.

So what happens there is: I install the GRECLIPSE "required" "Main Package". I create a new Groovy project, with a package under src called "test". Under that I make a file "test.groovy". First line of that:

package test
(incidentally I also have an annoying thing where the line I'm typing has a grey bar which obscures the line and makes it impossible to see what you're writing... anyway...)

So at that point I get both those errors: "- The type groovy.lang.MetaClass cannot be resolved. It is indirectly referenced from required .class files" & "- The type groovy.lang.GroovyObject cannot be resolved. It is indirectly referenced". I try cleaning the project, refreshing, closing and reopening Eclipse. Nothing doing.

Then I thought I'd add the other two options (Maven support and different compiler levels)... once I've adjusted the Eclipse-wide and project to 2.5.x I still have the same 2 errors showing.

I add a print line
println "hello world"

I try to run as a Groovy script: it doesn't print "hello world". Instead, the console shows this:

OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "groovy.lang.GroovyClassLoader"). To use archived non-system classes, this property must be not be set [NB this line is in red]
Error occurred during initialization of boot layer
java.lang.module.FindException: Module groovyExp not found
from required .class files"

This is exactly what happened yesterday.

@eric-milles
Copy link
Member

Can you take a screenshot that includes your Package/Project Explorer with some expanded nodes and your Groovy Editor when this error is showing?

@eric-milles
Copy link
Member

Here is just a small sample of running Eclipse 4.15 under Java 11 with a project that targets Java 11 and uses Groovy as well.

image

@Mrodent
Copy link
Author

Mrodent commented Mar 1, 2020

Thanks again, I really appreciate your helping with this! I made the screenshot. I doubt whether it'll tell you anything new.

Eclipse 2019-12 - Screenshot from 2020-03-01 09-24-13

Incidentally, you might be interested to know that I'm getting some unexpected errors when starting the Eclipse 2019-12 executable:

chris@M17A /opt/eclipse/eclipse_2019_12 $  ./eclipse 
org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
Starting Groovy-Eclipse compiler resolver. Specified compiler level: 2.5
973 org.codehaus.groovy_3.0.1.v202002291615-e1912 STARTING
971 org.codehaus.groovy_2.5.9.v202002291615-e1912 STARTING
974 org.codehaus.groovy_2.4.18.v202002291615-e1912 STARTING
Stopped bundle version 3.0.1.v202002291615-e1912
Skipped bundle version 2.5.9.v202002291615-e1912
Stopped bundle version 2.4.18.v202002291615-e1912
Refresh bundles:
967 org.eclipse.jdt.groovy.core_3.7.0.v202002291615-e1912 STARTING
965 org.codehaus.groovy.eclipse.ui_3.7.0.v202002291615-e1912 STARTING
964 org.codehaus.groovy.eclipse.refactoring_3.7.0.v202002291615-e1912 STARTING
961 org.codehaus.groovy.eclipse.core_3.7.0.v202002291615-e1912 STARTING
944 org.slf4j.api_1.7.10.v20170428-1633 RESOLVED
957 org.codehaus.groovy.eclipse.astviews_3.7.0.v202002291615-e1912 STARTING
  3 ch.qos.logback.classic_1.1.2.v20171220-1825 RESOLVED
  5 ch.qos.logback.slf4j_1.1.2.v20160301-0943 RESOLVED
958 org.codehaus.groovy.eclipse.codeassist_3.7.0.v202002291615-e1912 STARTING
962 org.codehaus.groovy.eclipse.dsl_3.7.0.v202002291615-e1912 STARTING
963 org.codehaus.groovy.eclipse.quickfix_3.7.0.v202002291615-e1912 STARTING
973 org.codehaus.groovy_3.0.1.v202002291615-e1912 UNINSTALLED
974 org.codehaus.groovy_2.4.18.v202002291615-e1912 UNINSTALLED
578 org.eclipse.m2e.logback.appender_1.14.0.20191209-1925 RESOLVED
959 org.codehaus.groovy.eclipse.codebrowsing_3.7.0.v202002291615-e1912 STARTING
579 org.eclipse.m2e.logback.configuration_1.14.0.20191209-1925 ACTIVE
org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
java.lang.IllegalStateException: BundleContext is no longer valid
	at org.eclipse.osgi.internal.framework.BundleContextImpl.checkValid(BundleContextImpl.java:1055)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.getBundle(BundleContextImpl.java:168)
	at org.eclipse.m2e.logback.configuration.LogPlugin.configureLogback(LogPlugin.java:118)
	at org.eclipse.m2e.logback.configuration.LogPlugin.access$2(LogPlugin.java:109)
	at org.eclipse.m2e.logback.configuration.LogPlugin$1.run(LogPlugin.java:64)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)
org.eclipse.m2e.logback.configuration: Logback config file: /media/chris/W10 D drive/My Documents/software projects/EclipseWorkspace_NEW/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.14.0.20191209-1925.xml
org.eclipse.m2e.logback.configuration: SLF4J logger factory is not an instance of LoggerContext: org.slf4j.impl.Log4jLoggerFactory
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/opt/eclipse/eclipse_2019_12/plugins/org.codehaus.groovy_2.5.9.v202002291615-e1912/lib/groovy-2.5.9-indy.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
log4j:WARN No appenders could be found for logger (org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersions).
log4j:WARN Please initialize the log4j system properly.

... and ... just to clarify: I simply expanded the Eclipse compressed file: I didn't follow a process of installation to install this version of Eclipse (or the one I'm currently using for my projects, 2019-06). How did you install your version of Eclipse?

@Mrodent
Copy link
Author

Mrodent commented Mar 1, 2020

PS thought you might need to see the expanded JRE Sys Lib:

JRE sys lib #1

and

JRE sys lib #2

@eric-milles
Copy link
Member

The messages in your log are normal. When the compile chooser bundle runs, it activates only one of the Groovy Compiler bundles. The others are uninstalled. And since you have the m2e logback bundle, this means a number of other bundles are refreshed as well. You can uninstall just logback if you want fewer warnings on startup: #981 (comment)

I see you have module-info.java in your package root. Does this mean you have a modular project? Can you share your classpath/modulepath? Just a look at the .classpath file should do.

Please note that modulepath entries are not very well supported for Groovy yet: #639

@Mrodent
Copy link
Author

Mrodent commented Mar 1, 2020

I don't know anything about module-info.java. As far as I'm aware I just accepted default choices when creating the Groovy project.

Here's my .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="GROOVY_DSL_SUPPORT">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="GROOVY_SUPPORT">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

@eric-milles
Copy link
Member

These attributes indicate that items are on the modulepath: <attribute name="module" value="true"/>

You can remove them in .classpath or edit via UI:
image

@eric-milles
Copy link
Member

Ah yes, when I add module-info to project, the error shows for various missing types. If I delete module-info, it goes away.

@eric-milles
Copy link
Member

You can also add requires org.codehaus.groovy; to your module-info to resolve the missing dependency.

@Mrodent
Copy link
Author

Mrodent commented Mar 2, 2020

Thanks. I tried adding the line requires org.codehouse.groovy;. The nasty red error mark disappeared, but when I ran as a Groovy script it still failed, with the following error message:

OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "groovy.lang.GroovyClassLoader"). To use archived non-system classes, this property must be not be set
Error occurred during initialization of boot layer
java.lang.module.FindException: Module groovyExp not found

However, when I deleted module-info.java I was indeed able to run the Groovy script ... it printed "hello".

So thank you very much... I can't currently accept the answer you've added on SO: if you care to change your answer to "delete module-info.java", or alternatively try and sort out the still remaining difficulty I describe above... ?

@eric-milles
Copy link
Member

Can you file a separate issue for Run As > Groovy Script not working? I think that is a separate issue.

You should be able to Run As > Java Application and it will run your script's contents if it is compiled to a class file. Run As > Groovy Script allows Groovy to do it's own compilation at runtime. You could also create unit tests to drive your code snippets. These should run fine as well.

@Mrodent
Copy link
Author

Mrodent commented Mar 2, 2020

Normally I was, until I stopped a few months ago, using Groovy-Eclipse (i.e. Eclipse Groovy Projects) precisely for that purpose: Groovy scripts, and nothing else. I use Gradle projects if I ever want to put together a "proper" Groovy app. More pressing for me perhaps than the "Groovy Script not working" issue (because deleting module-info.java is no big deal) is the on-going problems with import groovy.sql.Sql, so I propose to start a new issue on that... Marking this closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants