Compiling Groovy code
Groovy scripts are normally executed by running the groovy
command from the console; for example:
groovy someScript.groovy
The
groovy
command generates the JVM bytecode on the fly and immediately executes it. There are scenarios in which the Groovy code is required to be compiled to bytecode as a *.class
file. A typical case is when Java and Groovy code have to be used side-by-side for building a mixed Groovy/Java application.
Groovy has an answer to that by offering a compiler command, groovyc
(similarly to Java's javac
), that can also be invoked from the command line or through a build tool such as Ant (see the Integrating Groovy into the build process using Ant recipe), Maven (see the Integrating Groovy into the build process using Maven recipe), or Gradle (see the Integrating Groovy into the build process using Gradle recipe).
In this recipe, we are going to show you the principal purposes of the
groovyc
command.
Getting ready
The best way to show the Groovy compiler...