Tải bản đầy đủ (.pdf) (382 trang)

Gradle Effective Implementation Guide docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.5 MB, 382 trang )

www.it-ebooks.info
Gradle Effective
Implementation Guide
Empower yourself to automate your build
Hubert Klein Ikkink
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Gradle Effective Implementation Guide
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2012
Production Reference: 1181012
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-810-9
www.packtpub.com
Cover Image by Syarafuddin ()
www.it-ebooks.info


Credits
Author
Hubert Klein Ikkink
Reviewers
René Gröschke
Rajmahendra Hegde
Michał Huniewicz
James L. Williams
Acquisition Editor
Martin Bell
Lead Technical Editor
Sweny M. Sukumaran
Technical Editors
Dipesh Panchal
Unnati Shah
Dominic Pereira
Copy Editors
Brandt D’Mello
Insiya Morbiwala
Aditya Nair
Project Coordinator
Sai Gamare
Proofreader
Maria Gould
Clyde Jenkins
Mario Cecere
Indexer
Rekha Nair
Production Coordinator
Nitesh Thakur

Cover Work
Nitesh Thakur
www.it-ebooks.info
About the Author
Hubert Klein Ikkink was born in 1973 and lives in Tilburg, the Netherlands,
with his beautiful wife and gorgeous children. He is also known as mrhaki, which
is simply the initials of his name prepended by mr. He studied Information Systems
and Management at the Tilburg University. After nishing his studies he started to
work at a company which specialized in knowledge-based software. There he started
writing his rst Java software (yes, an applet!) in 1996. Over the years his focus
switched from applets, to servlets, to Java Enterprise Edition applications,
to Spring-based software.
In 2008 he wanted to have fun again when writing software. The larger projects
he was working on were more about writing conguration XML les, tuning
performance and less about real development in his eyes. So he started to look
around and noticed Groovy as a good language to learn about. He could still use
existing Java code, libraries, and his Groovy classes in Java. The learning curve isn’t
steep and to support his learning phase he wrote down interesting Groovy facts in
his blog with the title Groovy Goodness. He posts small articles with a lot of code
samples to understand how to use Groovy. Since November 2011 he is also a DZone
Most Valuable Blogger (MVB); DZone also posts his blog items on their site.
In 2010, 2011, and 2012 Hubert was invited to speak at Gr8Conf in Copenhagen,
Denmark. This is a very good conference with all the project leaders of Groovy and
Groovy-related projects. In November 2010 he presented a Gradle talk at the J-Fall
conference of the Dutch Java User Group. In November 2011 he presented about the
new features in Groovy 1.8 at the same conference. The conference is visited by 1000
Java developers and he got the chance to educate some of them about the greatness
of Gradle and Groovy.
Hubert works for a company called JDriven in the Netherlands. JDriven focuses
on technologies that simplify and improve development of enterprise applications.

Employees of JDriven have years of experience with Java and related technologies
and are all eager to learn about new technologies. Hubert works on projects using
Grails and Java combined with Groovy and Gradle.
www.it-ebooks.info
Acknowledgement
It was a great honor to be asked by Packt Publishing to write this book. I knew
beforehand it would be a lot of work and somehow needed to be combined with
my daytime job. I couldn’t have written the book without the help of a lot of people
and I would like to thank them.
First of all I would like to thank my family for supporting me while writing this
book. They gave me space and time to write the book. Thank you for your patience
and a big kiss for Kim, Britt, and Liam; I love you. I also like to thank my colleagues
at JDriven. They reviewed the pages I wrote and helped me by asking questions and
showing interest in the progress of the book. Of course I like to thank all the people
at Gradleware for making Gradle such a great build tool and René Gröschke for
reviewing the chapters in the book.
Finally I’d like to thank the great staff at Packt Publishing. Sai Gamare kept me on
schedule and made sure everything was submitted on time. I’d also like to thank
all the editors for reviewing the book. They really helped me to keep focus and be
concise with the text.
www.it-ebooks.info
About the Reviewers
René Gröschke has been working as a Software Engineer for more than
eight years now. He has worked on several international projects and regularly
shares his passion and experience of agile methodologies and software
craftsmanship with other developers at different national and international
conferences or with bachelor students of the Baden-Wuerttemberg Cooperative
State University (DHBW) in Germany.
Supporting Gradle and the Gradle community by providing plugins, patches,
screencasts, and talks since the early days, René has turned his hobby into his

occupation and is now part of the core developer team of Gradle working for
Gradleware. From time to time, he’s contributing to other open source projects,
such as Macports or Griffon.
Rajmahendra Hegde has been a Java Developer since 2000. He is currently
working for Logica as Project Lead/Architect. He is a User Group lead for Java
User Group – Chennai. He has contributed to JSRs and Scalaxia.com. He is the
committer for Visage. His primary areas of interest are JEE, JavaFX, JVM
Languages (Groovy, Scala, and Visage), NetBeans, and Gradle. You can
follow him at @rajonjava.
www.it-ebooks.info
Michał Huniewicz is a Software Developer, with several years of experience in
the JVM technologies. He has been involved in projects for a variety of industries,
including banking, press, nance, telecoms, and the government. He was also the
head developer of an award-winning community portal. Apart from being an active
blogger ( he is a passionate photographer and traveller.
He holds an M.Sc. degree in Computer Science from Adam Mickiewicz University.
Currently, he lives in London.
I would like to thank my parents, Rita and Andrzej, for their
continued support and for having faith in me.
James L. Williams is a developer based in Silicon Valley and a frequent
international conference speaker. He is the author of the book Learning HTML5 Game
Programming for Addison-Wesley. He blogs at and
tweets as @ecspike.
www.it-ebooks.info
www.PacktPub.com
Support les, eBooks, discount offers
and more
You might want to visit www.PacktPub.com for support les and downloads related
to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub

les available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.

Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital book
library. Here, you can access, read and search across Packt’s entire library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Starting with Gradle 7
Introducing Gradle 7
Declarative builds and convention over conguration 8
Support for Ant tasks and Maven repositories 8
Incremental builds 8
Multi-project builds 9
Gradle wrapper 9
Free and open source 9
Getting started 9
Installing Gradle 10

Writing our rst build script 11
Default Gradle tasks 12
Task name abbreviation 15
Executing multiple tasks 16
Command-line options 17
Logging options 18
Changing the build le and directory 19
Running tasks without execution 20
Gradle daemon 20
Proling 22
Understanding the Gradle user interface 22
Task Tree 24
Favorites 24
Command Line 25
Setup 25
www.it-ebooks.info
Table of Contents
[ ii ]
Summary 27
Chapter 2: Creating Gradle Build Scripts 29
Writing a build script 29
Dening tasks 30
Dening actions with the Action interface 32
Build scripts are Groovy code 33
Dening dependencies between tasks 34
Dening dependencies via tasks 36
Dening dependencies via closures 36
Setting default tasks 37
Organizing tasks 38
Adding a description to tasks 40

Grouping tasks together 40
Adding tasks in other ways 41
Using task rules 43
Accessing tasks as project properties 44
Adding additional properties to tasks 45
Avoiding common pitfalls 45
Skipping tasks 46
Using onlyIf predicates 46
Skipping tasks by throwing StopExecutionException 48
Enabling and disabling tasks 49
Skipping from the command line 50
Skipping tasks that are up-to-date 51
Summary 54
Chapter 3: Working with Gradle Build Scripts 55
Working with les 55
Locating les 55
Using le collections 58
Working with le trees 62
Copying les 64
Renaming les 65
Filtering les 66
Archiving les 68
Project properties 70
Dening custom properties in script 71
Passing properties via the command line 72
Dening properties via system properties 73
Adding properties via environment variables 73
Dening properties using an external le 74
www.it-ebooks.info
Table of Contents

[ iii ]
Using logging 75
Controlling output 80
Using the Gradle wrapper 82
Creating wrapper scripts 83
Customizing the Gradle wrapper 84
Summary 84
Chapter 4: Using Gradle for Java Projects 85
Using plugins 85
Getting started 86
Using the Java plugin 88
Working with source sets 92
Creating a new source set 95
Custom conguration 98
Working with properties 100
Creating documentation 104
Assembling archives 105
Summary 107
Chapter 5: Dependency Management 109
Dependency conguration 109
Repositories 112
Adding Maven repositories 113
Adding Ivy repositories 115
Adding a local directory repository 118
Dening dependencies 118
Using external module dependencies 119
Using project dependencies 124
Using le dependencies 124
Using client module dependencies 125
Using Gradle and Groovy dependencies 125

Accessing conguration dependencies 126
Setting dynamic versions 127
Resolving version conicts 128
Adding optional ANT tasks 129
Using dependency congurations as les 130
Summary 131
Chapter 6: Testing, Building, and Publishing Artifacts 133
Testing 133
Using TestNG for testing 140
Conguring the test process 144
Determining tests 146
www.it-ebooks.info
Table of Contents
[ iv ]
Logging test output 147
Generating test reports 149
Running Java applications 149
Running an application from a project 150
Running an application as task 151
Running an application with the application plugin 153
Creating a distributable application archive 154
Publishing artifacts 157
Uploading to a Maven repository 159
Multiple artifacts 162
Signing artifacts 163
Publishing signature les 165
Conguring conditional signing 167
Packaging Java Enterprise Edition applications 167
Creating a WAR le 167
Using the War plugin 169

Creating an EAR le 170
Using the Ear plugin 171
Summary 173
Chapter 7: Multi-project Builds 175
Working with multi-project builds 175
Executing tasks by project path 177
Using a at layout 178
Dening projects 179
Filtering projects 182
Dening task dependencies between projects 184
Dening conguration dependencies 185
Working with Java multi-project builds 186
Using partial builds 191
Using the Jetty plugin 194
Summary 198
Chapter 8: Mixed Languages 199
Using the Groovy plugin 199
Creating documentation with the Groovy plugin 205
Using the Scala plugin 206
Creating documentation with the Scala plugin 211
Summary 212
Chapter 9: Maintaining Code Quality 213
Using the Checkstyle plugin 213
Using the PMD plugin 221
Using the FindBugs plugin 224
www.it-ebooks.info
Table of Contents
[ v ]
Using the JDepend plugin 227
Using the CodeNarc plugin 229

Using the Sonar plugin 231
Summary 236
Chapter 10: Writing Custom Tasks and Plugins 237
Creating a custom task 237
Creating a custom task in the build le 238
Using incremental build support 240
Creating a task in the project source directory 243
Writing tests 246
Creating a task in a standalone project 247
Creating a custom plugin 249
Creating a plugin in the build le 250
Creating a plugin in the project source directory 252
Testing a plugin 254
Creating a plugin in a standalone project 255
Summary 258
Chapter 11: Using Gradle with Continuous Integration 259
Creating a sample project 259
Using Jenkins 264
Adding the Gradle plugin 265
Conguring Jenkins job 266
Running the job 270
Conguring artifacts and test results 272
Adding Gradle versions 275
Using JetBrains TeamCity 279
Creating a project 279
Running the project 286
Using Atlassian Bamboo 289
Dening a build plan 290
Running the build plan 298
Summary 306

Chapter 12: IDE Support 307
Using the Eclipse plugin 307
Customizing generated les 311
Customizing using DSL 312
Customizing with merge hooks 315
Customizing with XML manipulation 318
Merging conguration 319
Conguring WTP 319
Customizing le generation 323
www.it-ebooks.info
Table of Contents
[ vi ]
Using the IntelliJ IDEA plugin 327
Customizing le generation 329
Customizing using DSL 329
Customizing with merged hooks 332
Customizing with XML manipulation 333
Running Gradle in Eclipse 335
Installing Gradle plugin 336
Importing Gradle project 338
Running tasks 343
Editing build les 346
Running Gradle in IntelliJ IDEA 346
Installing the plugin 347
Importing a project 348
Running tasks 355
Summary 356
Index 357
www.it-ebooks.info
Preface

Gradle is the next-generation build automation. Not only does Gradle
use convention over conguration to provide good defaults, it is also adaptable for
use in every situation you encounter in daily development. Build logic is described
with a powerful DSL and empowers developers to create reusable and maintainable
build logic.
We will see more about Gradle in this book. We will learn about Gradle's features
with code samples throughout the book. We will learn how to write tasks, work
with les, and write build scripts using the Groovy DSL. Next, we will learn how
to use Gradle in projects to compile, package, test, check code quality and deploy
applications. And nally, we will see how to integrate Gradle with continuous
integration servers and development environments (IDEs).
After reading this book, we will know how to use Gradle in our daily
development. We can write tasks, apply plugins, and write build logic using
the Gradle build language.
What this book covers
Chapter 1, Starting with Gradle, introduces Gradle and explains how to install Gradle.
We will write our rst Gradle script and learn about the command-line and GUI
features of Gradle.
Chapter 2, Creating Gradle Build Scripts, looks at tasks as part of the Gradle build
scripts. We will see how we can dene tasks and use task dependencies to describe
build logic.
Chapter 3, Working with Gradle Build Scripts, covers more functionality that we can
apply in Gradle scripts. We will learn how to work with les and directories, apply
logging to our build scripts, and use properties to parameterize our build scripts.
www.it-ebooks.info
Preface
[ 2 ]
Chapter 4, Using Gradle for Java Projects, is all about using the Java plugin for Gradle
projects. Gradle offers several tasks and conguration conventions that make
working with Java projects very easy. We will see how we can customize the

conguration for projects that cannot follow the conventions.
Chapter 5, Dependency Management, covers the support for dependencies by Gradle.
We will learn how to use congurations to organize dependencies. We will also
see how we can use repositories with dependencies in our build scripts.
Chapter 6, Testing, Building, and Publishing Artifacts, is an introduction to Gradle
support for running tests from the build script. We will learn how we can build
several artifacts for a project and publish the artifacts to a repository so other
developers can reuse our code.
Chapter 7, Multi-project Builds, covers Gradle's support for multi-project builds.
With Gradle, we can easily congure multiple projects that are related to each
other. We will also see how Gradle can automatically build related or dependent
projects if necessary.
Chapter 8, Mixed Languages, is about the Scala and Groovy plugins that are included
with Gradle, to work with projects that have Scala or Groovy code.
Chapter 9, Maintaining Code Quality, introduces Gradle's code quality plugins. We
will see how we can use and congure the plugins to include code analysis in
our build process.
Chapter 10, Writing Custom Tasks and Plugins, covers what we need to do to write our
own custom tasks and plugins. We will see how we can decouple the denition and
usage of a custom task and plugin into separate source les. We will also learn how
we can reuse our custom tasks and plugins in other projects
Chapter 11, Using Gradle with Continuous Integration, is an introduction to the support of
several continuous integration tools for Gradle. We will learn how we can congure a
continuous integration server to automatically invoke our Gradle build scripts.
Chapter 12, IDE Support, looks at how Gradle can generate project les for Eclipse and
IntelliJ IDEA. We will also see how the IDEs support Gradle from within the IDE to
run (for example) tasks, and keep track of dependencies dened in Gradle scripts.
www.it-ebooks.info
Preface
[ 3 ]

What you need for this book
In order to work with Gradle and the code samples in the book, we need at least a
Java Development Kit (JDK 1.5 or higher), Gradle, and a good text editor. In Chapter
1, Starting with Gradle, we will see how we can install Gradle on our computer.
Who this book is for
This book is for you if you work on Java (Scala or Groovy) applications and
want to use build automation to compile, package, and deploy your application
automatically. You might have worked with other build automation tools such as
Maven or ANT, but this is not necessary to understand the topics in this book.
Conventions
In this book, you will nd a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "In our rst build we only have one
task, so the command
gradle h should work just ne."
A block of code is set as follows:
task helloWorld << {
println 'Hello world.'
}
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
apply plugin: 'java'
archivesBaseName = 'gradle-sample'
version = '1.0'
sourceSets {
api
}
task apiJar(type: Jar) {
appendix = 'api'

from sourceSets.api.output
}
www.it-ebooks.info
Preface
[ 4 ]
Any command-line input or output is written as follows:
hello-world $ gradle helloWorld
:helloWorld
Hello world.
BUILD SUCCESSFUL
Total time: 2.047 secs
New terms and important words are shown in bold. Words that you see on
the screen, in menus or dialog boxes for example, appear in the text like this:
"We select the plugin and click on the button Install without restart".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to
,
and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a
note in the SUGGEST A TITLE form on
www.packtpub.com or e-mail suggest@
packtpub.com
.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on

www.packtpub.com/authors.
www.it-ebooks.info
Preface
[ 5 ]
Customer support
Now that you are the proud owner of a Packt book, we have a number of things
to help you to get the most from your purchase.
Downloading the example code
You can download the example code les for all Packt books you have purchased
from your account at . If you purchased this book
elsewhere, you can visit and register to have
the les e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you nd a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you nd any errata, please report them by visiting ktpub.
com/support
, selecting your book, clicking on the errata submission form link, and
entering the details of your errata. Once your errata are veried, your submission
will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from />Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
Please contact us at

with a link to the suspected
pirated material.
We appreciate your help in protecting our authors, and our ability to bring
you valuable content.
Questions
You can contact us at if you are having a problem with
any aspect of the book, and we will do our best to address it.
www.it-ebooks.info
www.it-ebooks.info
Starting with Gradle
When we develop software, we write code, compile code, test our code, package our
code, and nally, distribute the code. We can automate these steps by using a build
system. The big advantage is that we have a repeatable sequence of steps. Each time,
the build system will follow the steps we have dened, so we can concentrate on
writing the actual code and not worry about the other steps.
Gradle is such a build system. In this chapter, we will explain what Gradle is and
how to use it in our development projects.
Introducing Gradle
Gradle is a tool for build automation. With Gradle, we can automate the compiling,
testing, packaging, and deployment of our software or other types of projects. Gradle
is exible but has sensible defaults for most projects. This means we can rely on the
defaults, if we don't want something special, but can still use the exibility to adapt
a build to certain custom needs.
Gradle is already used by big open source projects, such as Spring, Hibernate, and
Grails. Enterprise companies such as LinkedIn also use Gradle.
Let's take a look at some of Gradle's features.
www.it-ebooks.info
Starting with Gradle
[ 8 ]
Declarative builds and convention over

conguration
Gradle uses a Domain Specic Language (DSL) based on Groovy to declare builds.
The DSL provides a exible language that can be extended by us. Because the DSL
is based on Groovy, we can write Groovy code to describe a build and use the
power and expressiveness of the Groovy language. Groovy is a language for the
Java Virtual Machine (JVM), such as Java and Scala. Groovy makes it easy to work
with collections, has closures, and has a lot of useful features. The syntax is closely
related to the Java syntax. In fact, we could write a Groovy class le with Java syntax
and it would compile. But, using the Groovy syntax makes it easier to express the
code intent, and we need less boilerplate code than with Java. To get the most out of
Gradle, it is best to learn the basics of the Groovy language, but it is not necessary
to start writing Gradle scripts.
Gradle is designed to be a build language and not a rigid framework. The Gradle
core itself is written in Java and Groovy. To extend Gradle we can use Java and
Groovy to write our custom code. We can even write our custom code in Scala if
we want to.
Gradle provides support for Java, Groovy, Scala, Web, and OSGi projects, out of
the box. These projects have sensible convention over conguration settings that
we probably already use ourselves. But we have the exibility to change these
conguration settings, if needed, in our projects.
Support for Ant tasks and Maven repositories
Gradle supports Ant tasks and projects. We can import an Ant build and re-use all
the tasks. But we can also write Gradle tasks dependent on Ant tasks. The integration
also applies to properties, paths, and so on.
Maven and Ivy repositories are supported to publish or fetch dependencies.
So, we can continue to use any repository infrastructure we already have.
Incremental builds
With Gradle we have incremental builds. This means tasks in a build are only
executed if necessary. For example, a task to compile source code will rst check
whether the sources since the last execution of the task have changed. If the sources

have changed, the task is executed, but if the sources haven't changed, the execution
of the task is skipped and the task is marked as being up to date.
Gradle supports this mechanism for a lot of the provided tasks. But we can also
use this for tasks we write ourselves.
www.it-ebooks.info
Chapter 1
[ 9 ]
Multi-project builds
Gradle has great support for multi-project builds. A project can simply be dependent
on other projects or be a dependency for other projects. We can dene a graph of
dependencies between projects, and Gradle can resolve those dependencies for us.
We have the exibility to dene our project layout as we want.
Gradle has support for partial builds. This means Gradle will gure out if a project
that our project depends on needs to be rebuilt or not. And if the project needs
rebuilding, Gradle will do this before building our own project.
Gradle wrapper
The Gradle wrapper allows us to execute Gradle builds, even though Gradle is not
installed on a computer. This is a great way to distribute source code and provide
the build system with it, so that the source code can be built.
Also, in an enterprise environment, we can have a zero administration way for client
computers to build the software. We can use the wrapper to enforce a certain Gradle
version to be used, so the whole team is using the same version.
Free and open source
Gradle is an open source project and it is licensed under the Apache Software
License (ASL).
Getting started
In this section, we will download and install Gradle before writing our rst Gradle
build script.
Before we get and install Gradle, we must make sure we have a Java Development
Kit (JDK) installed on our computer. Gradle requires JDK 5 or higher. Gradle will

use the JDK found at the path set on our computer. We can check this by running
the following command on the command line:
java -version
Although Gradle uses Groovy, we don't have to install Groovy ourselves. Gradle
bundles the Groovy libraries with the distribution and will ignore a Groovy
installation already available on our computer.
www.it-ebooks.info
Starting with Gradle
[ 10 ]
Gradle is available on the Gradle website, at
From this page we can download the latest release of Gradle. Or, we can download
a previous version if we want to. We can choose among three different distributions
to download. We can download either the complete Gradle distribution, with
binaries, sources, and documentation, or only the binaries, or only the sources.
To get started with Gradle, we download the standard distribution with the binaries,
sources, and documentation. At the time of writing this book, the current release is
1.1. On computers with a Debian Linux operation sytem, we can install Gradle as a
Debian package. On computers with Mac OS X, we can use MacPorts or Homebrow
to install Gradle.
Installing Gradle
Gradle is packaged as a ZIP le for one of the three distributions. So, when we
have downloaded the Gradle full distribution ZIP le, we must unzip the le.
After unpacking the ZIP le we have the following:
• Binaries in the
bin directory
• Documentation with the user guide, Groovy DSL, and the API
documentation in the
docs directory
• A lot of samples in the
samples directory

• Source code for Gradle in the
src directory
• Supporting libraries for Gradle in the
lib directory
• A directory named
init.d where we can store Gradle scripts that
need to be executed each time we run Gradle
Once we have unpacked the Gradle distribution to a directory, we can open a
command prompt. We change the directory to
bin, which we extracted from the
ZIP le. To check our installation, we run gradle -v and we get output, listing
the JDK used and the library versions of Gradle:
$ gradle -v

Gradle 1.1

Gradle build time: Tuesday, July 31, 2012 1:24:32 PM UTC
Groovy: 1.8.6
www.it-ebooks.info

×