Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Gradle Effective Implementation Guide
Gradle Effective Implementation Guide

Gradle Effective Implementation Guide: A must-read for Java developers, this book will bring you bang up to date in the techniques of build automation using Gradle. A fully hands-on approach makes learning natural and entertaining.

eBook
€25.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Gradle Effective Implementation Guide

Chapter 1. Starting with Gradle

When we develop software, we write code, compile code, test our code, package our code, and finally, 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 defined, 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 flexible 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 flexibility 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.

Declarative builds and convention over configuration

Gradle uses a Domain Specific Language (DSL) based on Groovy to declare builds. The DSL provides a flexible 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 file 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 configuration settings that we probably already use ourselves. But we have the flexibility to change these configuration 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 first 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.

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 define a graph of dependencies between projects, and Gradle can resolve those dependencies for us. We have the flexibility to define our project layout as we want.

Gradle has support for partial builds. This means Gradle will figure 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 first 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.

Gradle is available on the Gradle website, at http://www.gradle.org/downloads. 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 file for one of the three distributions. So, when we have downloaded the Gradle full distribution ZIP file, we must unzip the file. After unpacking the ZIP file 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 file. 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
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_33 (Apple Inc. 20.8-b03-424)
OS: Mac OS X 10.7.4 x86_64

Here we can check whether the displayed version is the same as the distribution version we have downloaded from the Gradle website.

To run Gradle on our computer we only have to add $GRADLE_HOME/bin to our PATH environment variable. Once we have done that, we can run the gradle command from every directory on our computer.

If we want to add JVM options to Gradle, we can use the environment variables JAVA_OPTS and GRADLE_OPTS. The former is a commonly used environment variable name to pass extra parameters to a Java application. Similarly, Gradle uses the GRADLE_OPTS environment variable to pass extra arguments to Gradle. Both environment variables are used so we can set them both with different values. This is mostly used to set, for example, an HTTP proxy or extra memory options.

Writing our first build script


We now have a running Gradle installation. It is time to create our first Gradle build script. Gradle uses the concept of projects to define a related set of tasks. A Gradle build can have one or more projects. A project is a very broad concept in Gradle, but it is mostly a set of components we want to build for our application.

A project has one or more tasks. Tasks are a unit of work that need to be executed by the build. Examples of tasks are compiling source code, packaging class files into a JAR file, running tests, or deploying the application.

We now know that a task is part of a project, so to create our first task we also create our first Gradle project. We use the gradle command to run a build. Gradle will look for a file named build.gradle in the current directory. This file is the build script for our project. We define those of our tasks that need to be executed in this build script file.

We create a new file, build.gradle, and open it in a text editor. We type the following code to define our first Gradle task:

task helloWorld << {
  println 'Hello world.'
}

With this code we define a helloWorld task. The task will print the words "Hello world." to the console. println is a Groovy method to print text to the console and is basically a shorthand version of the Java method System.out.println.

The code between the brackets is a closure. A closure is a code block that can be assigned to a variable or passed to a method. Java doesn't support closures, but Groovy does. And because Gradle uses Groovy to define the build scripts, we can use closures in our build scripts.

The << syntax is, technically speaking, operator shorthand for the method leftShift(), which actually means "add to". So, we are defining here that we want to add the closure (with the statement println 'Hello world.') to our task with the name helloWorld.

First we save build.gradle, and then with the command gradle helloWorld, we execute our build:

hello-world $ gradle helloWorld
:helloWorld
Hello world.

BUILD SUCCESSFUL

Total time: 2.047 secs

The first line of output shows our line Hello world. Gradle adds some more output, such as the fact that the build was successful and the total time of the build. Because Gradle runs in the JVM, it must be started each time we run a Gradle build.

We can run the same build again, but with only the output of our task, by using the Gradle command-line option --quiet (or -q). Gradle will suppress all messages except error messages. When we use --quiet (or -q), we get the following output:

hello-world $ gradle --quiet helloWorld
Hello world.

Default Gradle tasks


We created our simple build script with one task. We can ask Gradle to show us the available tasks for our project. Gradle has several built-in tasks we can execute. We type gradle -q tasks to see the tasks for our project:

hello-world $gradle -q tasks

-----------------------------------------------------
All tasks runnable from root project
-----------------------------------------------------

Help tasks
----------
dependencies - Displays the dependencies of root project 'hello-world'.
help - Displays a help message
projects - Displays the sub-projects of root project 'hello-world'.
properties - Displays the properties of root project 'hello-world'.
tasks - Displays the tasks runnable from root project 'hello-world' (some of the displayed tasks may belong to subprojects).

Other tasks
-----------
helloWorld

To see all tasks and more detail, run with --all.

Here, we see our task helloWorld in the Other tasks section. The Gradle built-in tasks are displayed in the Help tasks section. For example, to see some general help information, we execute the help task:

hello-world $ gradle -q help

Welcome to Gradle 1.1.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

The properties task is very useful to see the properties available to our project. We haven't defined any property ourselves in the build script, but Gradle provides a lot of built-in properties. The following output shows some of the properties:

hello-world $ gradle -q properties

-----------------------------------------------------
Root project
-----------------------------------------------------

additionalProperties: {}
allprojects: [root project 'hello-world']
ant: org.gradle.api.internal.project.DefaultAntBuilder@6af37a62
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@16e7eec9
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler@54edd9de
asDynamicObject: org.gradle.api.internal.DynamicObjectHelper@4b7aa961
buildDir: /Users/mrhaki/Projects/gradle-book/samples/chapter1/hello-world/build
buildDirName: build
buildFile: /Users/mrhaki/Projects/gradle-book/samples/chapter1/hello-world/build.gradle
...

The dependencies task will show dependencies (if any) for our project. Our first project doesn't have any dependencies when we run the task, as the output shows:

hello-world $ gradle -q dependencies

-----------------------------------------------------
Root project
-----------------------------------------------------

No configurations

The projects task will display sub-projects (if any) for a root project. Our project doesn't have any sub-projects. So when we run the task projects, the output shows us that our project has no sub-projects.

hello-world $ gradle -q projects

-----------------------------------------------------
Root project
-----------------------------------------------------

Root project 'hello-world'
No sub-projects

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :tasks


Task name abbreviation


Before we look at more Gradle command-line options, it is good to learn about a real timesaving feature of Gradle: task name abbreviation. With task name abbreviation, we don't have to type the complete task name on the command line. We only have to type enough of the name to make it unique within the build.

In our first build we only have one task, so the command gradle h should work just fine. But then, we didn't take into account the built-in task help. So, to uniquely identify our helloWorld task, we use the abbreviation hello:

hello-world $ gradle -q hello
Hello world.

We can also abbreviate each word in a camel case task name. For example, our task name helloWorld can be abbreviated to hW:

hello-world $gradle -q hW
HelloWorld

This feature saves us the time spent in typing the complete task name and can speed up the execution of our tasks.

Executing multiple tasks


With just a simple build script, we already learned that we have a couple of default tasks besides our own task that we can execute. To execute multiple tasks we only have to add each task name to the command line. Let's execute our custom task helloWorld and the built-in task tasks, as follows:

hello-world $ gradle helloWorld tasks
:helloWorld
Hello world.
:tasks

-----------------------------------------------------
All tasks runnable from root project
-----------------------------------------------------

Help tasks
----------
dependencies - Displays the dependencies of root project 'hello-world'.
help - Displays a help message
projects - Displays the sub-projects of root project 'hello-world'.
properties - Displays the properties of root project 'hello-world'.
tasks - Displays the tasks runnable from root project 'hello-world' (some of the displayed tasks may belong to subprojects).

Other tasks
-----------
helloWorld

To see all tasks and more detail, run with --all.

BUILD SUCCESSFUL

Total time: 1.718 secs

We see the output of both the tasks. First, helloWorld is executed, followed by tasks. When executed, we see the task names prepended with a colon (:) and the output on the following lines.

Gradle executes the tasks in the same order as they are defined on the command line. Gradle will execute a task only once during the build. So even if we define the same task multiple times, it will be executed only once. This rule also applies when tasks have dependencies on other tasks. Gradle will optimize the task execution for us, and we don't have to worry about that.

Command-line options


The gradle command is used to execute a build. This command accepts several command-line options. We know the option --quiet (or -q) to reduce the output of a build. If we use the option --help (or -h or -?), we see the complete list of options:

hello-world $ gradle --help

USAGE: gradle [option...] [task...]

-?, -h, --help          Shows this help message.
-a, --no-rebuild        Do not rebuild project dependencies.
-b, --build-file        Specifies the build file.
-C, --cache             Specifies how compiled build scripts should be cached. Possible values are: 'rebuild' and 'on'. Default value is 'on' [deprecated - Use '--rerun-tasks' or '--recompile-scripts' instead]
-c, --settings-file     Specifies the settings file.
--continue              Continues task execution after a task failure. [experimental]
-D, --system-prop       Set system property of the JVM (e.g. -Dmyprop=myvalue).
-d, --debug             Log in debug mode (includes normal stacktrace).
--daemon                Uses the Gradle daemon to run the build. Starts the daemon if not running.
--foreground            Starts the Gradle daemon in the foreground. [experimental]
-g, --gradle-user-home  Specifies the gradle user home directory.
--gui                   Launches the Gradle GUI.
-I, --init-script       Specifies an initialization script.
-i, --info              Set log level to info.
-m, --dry-run           Runs the builds with all task actions disabled.
--no-color              Do not use color in the console output.
--no-daemon             Do not use the Gradle daemon to run the build.
--no-opt                Ignore any task optimization. [deprecated - Use '--rerun-tasks' instead]
--offline               The build should operate without accessing network resources.
-P, --project-prop      Set project property for the build script (e.g. -Pmyprop=myvalue).
-p, --project-dir       Specifies the start directory for Gradle. Defaults to current directory.
--profile               Profiles build execution time and generates a report in the <build_dir>/reports/profile directory.
--project-cache-dir     Specifies the project-specific cache directory. Defaults to .gradle in the root project directory.
-q, --quiet             Log errors only.
--recompile-scripts     Force build script recompiling.
--refresh               Refresh the state of resources of the type(s) specified. Currently only 'dependencies' is supported. [deprecated - Use '--refresh-dependencies' instead.]
--refresh-dependencies  Refresh the state of dependencies.
--rerun-tasks           Ignore previously cached task results.
-S, --full-stacktrace   Print out the full (very verbose) stacktrace for all exceptions.
-s, --stacktrace        Print out the stacktrace for all exceptions.
--stop                  Stops the Gradle daemon if it is running.
-u, --no-search-upward  Don't search in parent folders for a settings.gradle file.
-v, --version           Print version info.
-x, --exclude-task      Specify a task to be excluded from execution.

Logging options

Let's look at some of the options in more detail. The options --quiet (or -q), --debug (or -d), --info (or -i), --stacktrace (or -s), and --full-stacktrace (or -S) control the amount of output we see when we execute tasks. To get the most detailed output we use the option --debug (or -d). This option provides a lot of output with information about the steps and classes used to run the build. The output is very verbose, therefore we will not use it much.

To get a better insight into the steps that are executed for our task, we can use the --info (or -i) option. The output is not as verbose as with --debug, but it can give a better understanding of the build steps:

hello-world $ gradle --info helloWorld
Starting Build
Settings evaluated using empty settings file.
Projects loaded. Root project using build file '/Users/gradle/hello-world/build.gradle'.
Included projects: [root project 'hello-world']
Evaluating root project 'hello-world' using build file '/Users/gradle/hello-world/build.gradle'.
All projects evaluated.
Selected primary task 'helloWorld'
Tasks to be executed: [task ':helloWorld']
:helloWorld
Task ':helloWorld' has not declared any outputs, assuming that it is out-of-date.
Hello world.

BUILD SUCCESSFUL

Total time: 1.535 secs

If our build throws exceptions, we can see the stack trace information with the options --stacktrace (or -s) and --full-stacktrace (or -S). The latter option will output the most information and is the most verbose. The options --stacktrace and --full-stracktrace can be combined with the other logging options.

Changing the build file and directory

We created our build file with the name build.gradle. This is the default name for a build file. Gradle will look for a file with this name in the current directory, to execute the build. But we can change this with the command-line options --build-file (or -b) and --project-dir (or -p).

Let's run the Gradle command from the parent directory of our current directory:

hello-world $ cd ..
$ gradle --project-dir hello-world -q helloWorld
Hello world.

And we can also rename build.gradle to, for example, hello.build and still execute our build:

hello-world $ mv build.gradle hello.build
hello-world $ gradle --build-file -q helloWorld
Hello world.

Running tasks without execution

With the option --dry-run (or -m), we can run all the tasks without really executing them. When we use the dry run option, we can see which tasks are executed, so we get an insight into which tasks are involved in a certain build scenario. And we don't have to worry if the tasks are actually executed. Gradle builds up a Directed Acyclic Graph (DAG) with all the tasks before any task is executed. The DAG is built so that tasks will be executed in order of dependencies and so that a task is executed only once.

hello-world $ gradle --dry-run helloWorld
:helloWorld SKIPPED

BUILD SUCCESSFUL

Total time: 1.437 secs

Gradle daemon

We already learned that Gradle is executed in a Java Virtual Machine, and each time we invoke the gradle command, a new Java Virtual Machine is started, the Gradle classes and libraries are loaded, and the build is executed. We can reduce the build execution time if we don't have to load a JVM, Gradle classes, and libraries, each time we execute a build. The command-line option, --daemon, starts a new Java process that will have all Gradle classes and libraries already loaded, and then we execute the build. The next time when we run Gradle with the --daemon option, only the build is executed, because the JVM, with the required Gradle classes and libraries, is already running.

The first time we execute gradle with the --daemon option, the execution speed will not improve, because the Java background process has not started as yet. But the next time around, we will see a major improvement:

hello-world $ gradle --daemon helloWorld
:helloWorld
Hello world.

BUILD SUCCESSFUL

Total time: 0.59 secs

Even though the daemon process has started, we can still run Gradle tasks without using the daemon. We use the command-line option --no-daemon to run a Gradle build without utilizing the daemon:

hello-world $ gradle --no-daemon helloWorld
:helloWorld
Hello world.

BUILD SUCCESSFUL

Total time: 1.496 secs

To stop the daemon process, we use the command-line option --stop:

$ gradle --stop
Stopping daemon.
Gradle daemon stopped.

This will stop the Java background process completely.

To always use the --daemon command-line option, without typing it every time we run the gradle command, we can create an alias—if our operating system supports aliases. For example, on a Unix-based system we can create an alias and then use the alias to run the Gradle build:

hello-world $ alias gradled='gradle --daemon'
hello-world $ gradled helloWorld
:helloWorld
Hello world.

BUILD SUCCESSFUL

Total time: 0.59 secs Instead

Instead of using the --daemon command-line option, we can use the Java system property org.gradle.daemon to enable the daemon. We can add this property to environment variable GRADLE_OPTS, so that it is always used when we run a Gradle build.

hello-world $ export GRADLE_OPTS="-Dorg.gradle.daemon=true"
hello-world $ gradle helloWorld
:helloWorld
Hello world.

BUILD SUCCESSFUL

Total time: 0.707 secs

Profiling

Gradle also provides the command-line option --profile . This option records the time that certain tasks take to complete. The data is saved in an HTML file in the directory build/reports/profile. We can open this file in a web browser and see the time taken for several phases in the build process. The following image shows the HTML contents of the profile report:

Understanding the Gradle user interface


Finally, we take a look at the --gui command-line option. With this option, we start a graphical shell for our Gradle builds. Until now, we have used the command line to start a task. With the Gradle GUI, we have a graphical overview of the tasks in a project, and we can execute them by simply double-clicking on them.

To start the GUI, we invoke the following command:

hello-world $ gradle --gui

A window is opened with a graphical overview of our task tree. We have only one task, which is listed in the task tree, as shown in the following screenshot:

The output of a running task is shown in the bottom part of the window. When we start the GUI for the first time, the tasks task is executed and we see the output in the window.

Task Tree

The Task Tree tab shows projects and tasks found in our build project. We can execute a task by double-clicking on the task name.

By default all tasks are shown, but we can apply a filter to show or hide certain projects and tasks. The Filter button opens a new dialog window where we can define which tasks and properties are part of the filter. The Toggle filter button makes the filter active or inactive.

We can also right-click on the project and task names. This opens a context menu where we can choose whether to execute the task, add it to the favorites, hide it (adds it to the filter), or edit the build file. If we click on Edit File, and if the .gradle extension is associated with a text editor in our operating system, the editor is opened with the content of the build script. These options can be seen in the following screenshot:

Favorites

The Favorites tab stores tasks we want to execute regularly. We can add a task by right-clicking on the task in the Task Tree tab and selecting the Add To Favorites menu option. Alternatively, we can open the Favorites tab, click on the Add button and manually enter the project and task name we want to add to our favorites list. We can see the Add Favorite dialog window in the following screenshot:

Command Line

On the Command Line tab, we can enter any Gradle command we normally would enter on the command prompt. The command can be added to Favorites as well. We can see the Command Line tab contents in the following screenshot:

Setup

The last tab is the Setup tab. Here, we can change the project directory, which is set by default to the current directory.

We learned about the different logging levels as command-line options previously in this chapter. In the GUI, we can select the logging level from the Log Level drop-down box with the different log levels. We can choose one of Debug, Info, Lifecyle, and Error as the log levels. The Error log level only shows errors and is the least verbose, while Debug is the most verbose log level. The Lifecyle log level is the default log level.

Here we can also set how detailed the exception stack trace information should be. In the section Stack Trace Output we can choose between the following three options:

  • Exceptions only: For showing only exceptions when they occur; this is the default value

  • Standard Stack Trace: For showing more stack trace information for the exceptions

  • Full Stack Trace: For the most verbose stack trace information for exceptions

If we enable the option Only Show Output When Errors Occur, we get output from the build process only if the build fails; otherwise we don't get any output.

Finally, we can define a different way to start Gradle for the build, with the option Use Custom Gradle Executor . For example, we can define a different batch or script file with extra setup information to run the build process. The following screenshot shows the Setup tab page along with all the options we can set:

Summary


So now, we have learned how to install Gradle on our computers. We have written our first Gradle build script with a simple task.

We have seen how to use the tasks built-in to Gradle to get more information about a project. We learned how to use the command-line options to help us run the build scripts. And, we have looked at the Gradle graphical user interface and how we can use it to run Gradle build scripts.

In the next chapter we will take a further look at tasks. We will learn how to add actions to a task. We will write more complex tasks where tasks will depend on other tasks. And we will learn how Gradle builds up a task graph internally and how we can use this in our projects.

Left arrow icon Right arrow icon

Key benefits

  • Learn the best of Gradle
  • Work easily with multi-projects
  • Apply Gradle to your Java, Scala and Groovy projects

Description

Gradle is the next generation in build automation. It uses convention-over-configuration to provide good defaults, but is also flexible enough to be usable 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."Gradle Effective Implementation Guide" is a great introduction and reference for using Gradle. The Gradle build language is explained with hands on code and practical applications. You learn how to apply Gradle in your Java, Scala or Groovy projects, integrate with your favorite IDE and how to integrate with well-known continuous integration servers.Start with the foundations and work your way through hands on examples to build your knowledge of Gradle to skyscraper heights. You will quickly learn the basics of Gradle, how to write tasks, work with files and how to use write build scripts using the Groovy DSL. Then as you develop you will be shown how to use Gradle for Java projects. Compile, package, test and deploy your applications with ease. When you've mastered the simple, move on to the sublime and integrate your code with continuous integration servers and IDEs. By the end of the "Gradle Effective Implementation Guide" you will be able to use Gradle in your daily development. Writing tasks, applying plugins and creating build logic will be second nature.

Who is this book for?

If you are a Java developer who wants to automate compiling, packaging and deploying your application this book is for you.

What you will learn

  • Create Gradle build scripts from clear examples
  • Write build logic with the Gradle build language
  • Compile, test and check your Java, Scala and Groovy applications
  • Write your own custom tasks and plugins
  • Use Gradle on continous integrations servers Jenkins, TeamCity and Bamboo
  • Integrate Gradle with Eclipse and IntelliJ IDEA
Estimated delivery fee Deliver to Germany

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 25, 2012
Length: 382 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518109
Vendor :
Apache
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Germany

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Oct 25, 2012
Length: 382 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518109
Vendor :
Apache
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 79.98
Gradle Effective Implementation Guide
€37.99
Groovy 2 Cookbook
€41.99
Total 79.98 Stars icon

Table of Contents

12 Chapters
Starting with Gradle Chevron down icon Chevron up icon
Creating Gradle Build Scripts Chevron down icon Chevron up icon
Working with Gradle Build Scripts Chevron down icon Chevron up icon
Using Gradle for Java Projects Chevron down icon Chevron up icon
Dependency Management Chevron down icon Chevron up icon
Testing, Building, and Publishing Artifacts Chevron down icon Chevron up icon
Multi-project Builds Chevron down icon Chevron up icon
Mixed Languages Chevron down icon Chevron up icon
Maintaining Code Quality Chevron down icon Chevron up icon
Writing Custom Tasks and Plugins Chevron down icon Chevron up icon
Using Gradle with Continuous Integration Chevron down icon Chevron up icon
IDE Support Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(10 Ratings)
5 star 50%
4 star 20%
3 star 10%
2 star 20%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Rob Mar 25, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In most of the projects if contributed to Maven still is the build tool of choice. Based on my still growing interest for Groovy (and Grails) I noticed that Gradle could be a valid alternative.The Book "Gradle Effective Implementation Guide" helped me to get up to speed with Gradle quickly and to understand the principles behind it.It's well written, does not expect any prior knowledge of Gradle and contains lot of examples.I really enjoyed reading this book, playing around we the examples and getting familiar with the possibilities Gradle offers.Based on this experience I'm now able to judge if Gradle is a valid alternative buildtool on a per project basis and believe it will be in lots of them.
Amazon Verified review Amazon
Chetan Pandey Feb 16, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
My Recent Job, they didnt want to use Ant or Maven and it was proposed that we should use Gradle.I was lucky our Corporate Library had received a complimentary copy of this book.I used it to build several recipes and was able to master Gradle in No Time.Initially due to a lack of lot of infon on the Web, I almost gave up when this book made a difference.
Amazon Verified review Amazon
Coen Jansen Apr 22, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is an excellent way to get in to Gradle. It starts with the basics and builds from there.It is a practical guide to using Gradle with a lot of code examples that show you its possibilities.Because of al these code examples it's also a great reference when you're working on a Gradle build.In the books code samples you can see the genius of its author. He is well known in the Groovy and Grails communityfor live coding presentations and for his mr HAKI blog which is busting at the seams withpractical Groovy, Grails and Gradle posts.A book worth reading and well worth the investment!
Amazon Verified review Amazon
Spencer Allain Dec 30, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Gradle is a build automation tool that combines the respective strengths of ANT and Maven, with a more user friendly DSL (Domain Specific Language) based upon the features of the Groovy programming language.The author, better known as MrHaki, has been blogging about Gradle tips, tricks and patterns since 2009, and Groovy and Grails for even longer. The first 10 chapters of the book are well organized to take a reader with little to no knowledge of Gradle and walk them through basic concepts, then introduce common usages, and finally provide practical full build lifecycle examples. The final two chapters focus upon integration with popular CI servers and IDEs. More experienced Gradle users will appreciate the diversity of examples along with the detailed explanations of configuration options that are often overlooked.As a user of Gradle since the 0.5 release, it was refreshing to learn new things from a book that is also so effective at introducing the basics. If you are looking for an easy read, with well documented examples, then MrHaki's Gradle Effective Implementation Guide should be on your short list.
Amazon Verified review Amazon
James Sugrue Mar 17, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Until recently, Ant has been my build system of choice: functional, proven and, it just works. So, I was intrigued to see what Gradle could provide instead.The book begins with a really good introduction into what Gradle actually is. Useful for Gradle newbies like me, but most people can probably afford to skip it. The book then goes through the main things you'll want to do in your Gradle build scripts; using tasks and dealing with files and directories; before showing how easy it is to use Gradle for your Java projects. Later on the book illustrates how you can use the Scala or Groovy plugins to build projects for those languages, and how to build multiple projects that are dependent on each other.I found the chapter on writing custom tasks and plugins to be particularly useful. Most importantly, the author explains how you can write tests for your custom plugins to ensure they work as expected. As you'd expect, Gradle has good IDE and continuous integration support, all of which is explained in the last chapters.The book will probably appeal more to people who are new to Gradle. I found the explanations to be be really detailed and useful. Whether I'll use Gradle for my next project, I'm not sure - but it certainly is tempting
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela