Groovy in Eclipse not recognizing imports
Solution 1
Forgot to actually build the project. Ouch. (build automatically was turned off in Eclipse)
Solution 2
Three possibilities:
- The script is not in a source folder
- The script being referred to is not in a source folder.
- One or both scripts are in "script folders". Script folders are folders where scripts go. Groovy files in script folders are not sent to the compiler and therefore scripts in script folders cannot reference each other. Check out your script folder at Preferences -> Groovy -> Compiler. Also, as of groovy-eclipse 2.6.1, there are project specific script folders, so also check in your project properties.
Solution 3
I was having this problem when I imported to the IDE an existing groovy project before having installed the "Groovy Development Tools" plugin.
I installed the Groovy plugin and restarted the IDE, but my project was still broken.
So I deleted the project and I imported it again, and then the problem was gone.
Comments
-
smcg almost 2 years
I am attempting to run a Groovy script in Eclipse but Eclipse is seemingly ignoring all of my import statements. If I hover over the errors it tells asks me to import the appropriate class (clicking on it does nothing).
I have the required jars in my build path and class path.
Sample code, pretty standard:
package scripts.blah import foo.Bar; class FooMain { static main(String[] args){ Bar bar = new Bar(); } }
Groovy:unable to resolve class Bar
Any help would be appreciated.
-
smcg about 12 yearsThanks for the tips, I'll try this out on Monday.
-
smcg about 12 yearsSorry for the anticlimax, but turns out I just needed to build the project (build automatically was turned off). Not sure whether the question should be closed or how this works.
-
Jirong Hu about 8 yearsI have the same error "Unable to resolve class" in external libraries such as "import com.beust.jcommander.JCommander". I am using Gradle and the gradlew compileGroovy works fine from command line.