Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Groovy 2 Cookbook

You're reading from   Groovy 2 Cookbook Java and Groovy go together like ham and eggs, and this book is a great opportunity to learn how to exploit Groovy 2 to the full. Packed with recipes, both intermediate and advanced, it's a great way to speed up and modernize your programming.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781849519366
Length 394 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Luciano Fiandesio Luciano Fiandesio
Author Profile Icon Luciano Fiandesio
Luciano Fiandesio
Andrey Adamovich Andrey Adamovich
Author Profile Icon Andrey Adamovich
Andrey Adamovich
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Groovy 2 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Groovy 2. Using Groovy Ecosystem FREE CHAPTER 3. Using Groovy Language Features 4. Working with Files in Groovy 5. Working with XML in Groovy 6. Working with JSON in Groovy 7. Working with Databases in Groovy 8. Working with Web Services in Groovy 9. Metaprogramming and DSLs in Groovy 10. Concurrent Programming in Groovy Index

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:

  1. Open a shell in your operating system and type:

    git clone https://github.com/groovy/groovy-core.git
    
  2. 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
    
  3. 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).

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime