Intermixing Groovy and Java with Joint Compilation

If the Groovy classes are precompiled, then we can use the .class files or JARs readily from Java. Java sees no difference between the bytecode from Java and Groovy; we’ll have to add the Groovy JAR (discussed earlier) in our classpath, much like how we’ll have JARs for Spring, Hibernate, or other frameworks/libraries we use.

What if we have Groovy source code instead of bytecode? Remember, when our Java class depends on other Java classes, javac will compile any Java classes it deems necessary if it does not find their bytecode. However, javac does not extend that kindness to Groovy. Fortunately, groovyc supports joint compilation. When we compile Groovy code, it determines whether any Java ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.