Groovy in Eclipse not recognizing imports

12,301

Solution 1

Forgot to actually build the project. Ouch. (build automatically was turned off in Eclipse)

Solution 2

Three possibilities:

  1. The script is not in a source folder
  2. The script being referred to is not in a source folder.
  3. 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.

Share:
12,301
smcg
Author by

smcg

My github: https://github.com/s-mcg

Updated on July 04, 2022

Comments

  • smcg
    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
    smcg about 12 years
    Thanks for the tips, I'll try this out on Monday.
  • smcg
    smcg about 12 years
    Sorry 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
    Jirong Hu about 8 years
    I 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.