Grails is built on Groovy which is known as a dynamic language. The dynamic nature of Groovy offers a lot of powerful features but also defers the detection of errors from compile time to runtime. To shorten the feedback cycle for your code Groovy has a handy annotation which will make sure that your classes is are statically compiled. This will give you fast feedback for a lot of mistakes and you also will benefit from the increased performance offered by the static complication. Unfortunately in Grails this annotation prevents you from using the very useful dynamic GORM methods like list(), get() and the dynamic finder methods. Groovy does not recognize these Grails methods during compile time; see the example below.

@CompileStatic
class BookController(){

     def save(){
       //This will successfully compile
    }

    def get(){
       Book.findByName(params.name)
       //this will throw a compile error since the findByName method is not known
       //at compile time
    }

    @CompileStatic(TypeCheckingMode.SKIP)
    def delete(){
       //by setting the TypeCheckinMode, this method will be skipped
    }
}

Grails version 2.4 comes with a new annotation called @GrailsCompileStatic. This annotation is able to recognize specific Grails code constructs and will make sure they will be accessed in a dynamic way.

@GrailsCompileStatic
class BookController(){

    def save(){
       //This will succesfully compile
    }

    def get(){
       Book.findByName(params.name)
      //this will now compile succesfully!
    }

    @GrailsCompileStatic(TypeCheckingMode.SKIP)
    def delete(){
      //by setting the TypeCheckinMode, this method will be skipped.
      //This still works in the new Grails annotation
    }
}
shadow-left