Groovy:Apparent variable xyz was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:

Nix picture Nix · Apr 2, 2013 · Viewed 9.9k times · Source

I am getting this "error" in an Spring Tool Suite for all of my domain classes. Its not really an error, because it compiles fine. But it's masking real compile errors, how can I get rid of it ? They are in the same package, so I dont need the import, if I add the import it says it can't find the class...

So the following code produce a red x

Groovy:Apparent variable 'ExampleB' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:

package domain.com.so;

class ExampleA {
    static belongsTo  = [exampleB: ExampleB]
    static constraints = {
    }
}

And this code produces a simpilar error:

Groovy:Apparent variable 'ExampleA' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:

package domain.com.so;

class ExampleB {
    static hasMany  = [exampleAs: ExampleA]
    static constraints = {
    }
}

Answer

user800014 picture user800014 · Apr 3, 2013

Normally when STS complains something like this I run

grails clean 

and

grails compile --refresh-dependencies