Building Groovy from source
In this recipe, we introduce a procedure for building Groovy from the source code. The only requirement needed to build Groovy from source is Java JDK 1.7 or higher.
Java 7 is required to leverage the new invokedynamic
instruction used by Groovy 2. You can read more about the benefits of invokedynamic
in the Running Groovy with invokedynamic support recipe.
Getting ready
Like many of today's open source projects, Groovy source is maintained on GitHub. GitHub is a website that provides a Git hosting service. You have probably heard of Git, the version control system started by the Linux creator, Linus Torvalds.
In order to build Groovy, you need a local copy of the source code that must be fetched from GitHub via Git. If you are running a Linux or OS X operating system, chances are that you already have Git installed on your box.
For Windows, there are several ways to install Git. You may want to use Cygwin (http://www.cygwin.com/) or the officially released version available on the Git website (http://git-scm.com/download/win).
For this recipe, we assume that a recent version of Git is available in your shell. To test that Git is indeed available, open a shell and type the following command:
git --version
How to do it...
Assuming that git
is installed and operational, we can proceed with the following steps to build Groovy from source:
Open a shell in your operating system and type:
git clone https://github.com/groovy/groovy-core.git
Wait for Git to fetch all the source code and proceed to build Groovy. On Windows, open a DOS shell, move to the
groovy-core
folder you just cloned, and type:gradlew.bat clean dist
On Linux or Mac OS X, open a shell, move to the
groovy-core
folder, and type:./gradlew clean dist
If you already have Gradle installed, you can run the following command instead:
gradle clean dist
How it works...
The git clone
command in the first step fetches the Groovy repository, around 125 MB, so be patient if you are on a slow connection. Groovy has switched to the Gradle build tool from Ant. The gradlew
command is a convenient wrapper for Gradle that takes care of downloading all the required dependencies and triggering the build. Chapter 2, Using Groovy Ecosystem, has a whole recipe dedicated to Gradle, so you may want to take a look at the Integrating Groovy into the build process using Gradle recipe to know more about this awesome tool. Furthermore, several recipes in this book will make use of Gradle to build the code examples.
The build process will download the required dependencies and compile the code. Upon successful compilation, the build will generate a ZIP file named groovy-binary-2.x.x-SNAPSHOT.zip
that contains the binaries, under /target/distributions
. Install the binaries in the same way as explained in the Installing Groovy on Windows and Installing Groovy on Linux and OS X recipes.
Note how two types of Groovy binaries are generated: a normal version and an indy
version. The indy
version will leverage the invokedynamic
feature (see also the Running Groovy with invokedynamic support recipe).