Specs: 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". Under test I put a file, "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. It is indirectly referenced from required .class files
- The type groovy.lang.GroovyObject cannot be resolved. It is indirectly referenced from required .class files
I have tried multiple strategies: restarting Eclipse, cleaning the project, removing and putting back the JRM for the project. 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. But this is a (pure) Groovy project, not Gradle, and the "Refresh" option is not available.
By the way, when I look at this problem in the "Problems" the error type is said to be "Java Problem".
later
It's been suggested that the cause might be Java 11. This is an interesting idea. 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. 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. So Eclipse Groovy-handling is mercifully "bypassed".
I am thus beginning to suspect that the Groovy-Eclipse add-in may be the culprit. 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. Even after several attempts to install both the "release" and "snapshot" versions of Groovy-Eclipse for this version of Eclipse (i.e. here), I cannot start the simplest of Groovy projects in that IDE.
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.
Add "requires org.codehaus.groovy;" to your module-info.java
Related
Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage
Specs: OS Linux Mint 18.3, Groovy 2.5.8, Eclipse 2019-06, Java 11.
I want to make a simple connection to a MySQL dbase from a Groovy script.
So far the script looks like this:
import java.sql.*
import groovy.sql.Sql
println "hello world"
This runs fine at the CLI (with the usual "reflection" warnings of course).
Whatever I do in Eclipse I'm getting a horrid white-cross-in-red-box (bane of my life) which says "Groovy: unable to resolve class groovy.sql.Sql".
I've looked at the project's settings for Java and Groovy. I've tried removing and then adding back the JRE (Java 11) for the project. I've tried cleaning the project. I've tried restarting Eclipse.
In other words, I've tried doing most of the things (ways of fighting back) that I've learnt from many years of bitter struggle against my mortal enemy Eclipse.
Googling the error has produced only people who misspelt things.
By the way, when you look at things in the "Problems" panel, the error is described as a "Java Problem".
I'm feeling I must be doing something immensely stupid and that the answer is easy. Anyone got any ideas?
Groovy 2.5 does not have the same "fat jar" packaging as earlier Groovy versions did. You need to add groovy-sql to your project or to your ~/.groovy/lib directory. And you may need to add "requires org.codehaus.groovy.sql;" to your module-info (if your project is modular).
I've reinstalled my windows machine and installed Java 13, Maven 3.6.2 to finally run my projects. I use java immutable classes which get generated by maven. I have a problem where only SOME generated sources are picked up and some are missing in the editor (shows errors). However, I'm able to run the application through IntelliJ and build with Maven.
Any ideas on how to fix this?
Do note that I've gone through a number of similar questions where ALL generated-sources are not picked up and I have the correct settings for picking up source files.
Kind of a funny situation here... Everything worked fine, but I found that one of the interfaces I used (from which a generated source is made) had another generated source marked as red (as if not imported). Importing the full path for it suddenly resolved the issue.
common.advert.Price getPrice();
My guess this is an editor problem that I have.
I came across a Maven project which has Groovy files in it. Those Groovy files were not getting recognized during initial compilation. So, I added groovy libraries in build path.
Due to that, when autobuild is triggered it shows the following error window:
Also, I am not able to decompile the dependent jars and all the projects went into error state.
I tried restarting my eclipse and it asked me to install the following plugins:
When I click on install, it prompts me the following error window:
I am not sure if reverting back all my changes of adding Groovy libraries is a good idea! Any leads on handling this situation will be appreciated.
It sounds like you added the Groovy Development Tools to eclipse. GDT patches the Java Development Tools (and provides LanguageSupportFactory class mentioned above). If you use the incorrect version of GDT to patch JDT, eclipse can end up in a very bad state.
I recommend looking at Help > About Eclipse Platform > Installation Details > Installation History. You can revert to a previous state where GDT was not installed. If you want to add back GDT, be sure you use the update site that matches the version of eclipse you are using.
Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage