Can anyone explain the Groovy compiler works? Does it compile:
Groovy code -> Java code -> Bytecode
Groovy code -> Bytecode
Some other method
The groovyc compiler is a necessity for compiling Groovy and Java together simultaneously. It can also be useful for compiling . class files to execute without need for recompilation every time the script is run.
Unlike Java, a Groovy source code file can be executed as an (uncompiled) script, if it contains code outside any class definition, if it is a class with a main method, or if it is a Runnable or GroovyTestCase. A Groovy script is fully parsed, compiled, and generated before executing (similar to Python and Ruby).
Groovy scripts can use any Java classes. They can be compiled to Java bytecode (in . class files) that can be invoked from normal Java classes. The Groovy compiler, groovyc, compiles both Groovy scripts and Java source files, however some Java syntax (such as nested classes) is not supported yet.
Groovy is both compiled and interpreted language as groovy code is compiled to JVM byte code also which is interpreted at runtime.
Groovy parses the source code with antlr via the groovy grammar description, then generates bytecode using asm
It does not require javac
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With