Should Groovy @CompileStatic classes still include metaclass code?

590 views Asked by At

I'm starting to incorporate some Groovy classes into my Maven-built Spring application, primarily to reduce boilerplate on a lot of classes that are POJOs and value objects. (For comparison, I've been using Roo to handle the boilerplate, but Roo is getting increasingly flaky with newer versions of Spring and Maven.) One of my Spring Data MongoDB classes looks like this:

@Document
class ConcreteProcessingJob implements ImageAssetProcessingJob {

    @Id
    String id

    @Indexed(unique = true, sparse = true)
    String jobId

    @NotNull
    @Past
    Date started

    // more of the same
}

Since these are just run-of-the-mill struct objects, I don't need or want the complexity and overhead of Groovy's metaclassing and call-siting; I just want the equivalent to a POJO. I've tried annotating the classes with @CompileStatic, but while a couple of the calls in the bytecode have replaced invokedynamic with invokevirtual, I am still getting huge .class files with several large Groovy methods and data structures; one class that's nothing but an empty subclass that reifies a generic superclass is over 5k of bytecode.

I've compiled the code both from within Eclipse and from the command line, using the groovy-eclipse-compiler (2.8.0-01) both times, and while there are some minor differences, the bytecode still has all the dynamic "bloat" in it. The Groovy dependency I'm pulling in is 2.3.2, and I have my Java targets set at 1.7.

Is it expected for even an entire class marked @CompileStatic to have all of the Groovy metadata and -code compiled into it? If so, is there some other way to disable that?

0

There are 0 answers