Book Image

Gradle Effective Implementations Guide - Second Edition

By : Hubert Klein Ikkink
Book Image

Gradle Effective Implementations Guide - Second Edition

By: Hubert Klein Ikkink

Overview of this book

Gradle is a project automation tool that has a wide range of applications. The basic aim of Gradle is to automate a wide variety of tasks performed by software developers, including compiling computer source code to binary code, packaging binary codes, running tests, deploying applications to production systems, and creating documentation. The book will start with the fundamentals of Gradle and introduce you to the tools that will be used in further chapters. You will learn to create and work with Gradle scripts and then see how to use Gradle to build your Java Projects. While building Java application, you will find out about other important topics such as dependency management, publishing artifacts, and integrating the application with other JVM languages such as Scala and Groovy. By the end of this book, you will be able to use Gradle in your daily development. Writing tasks, applying plugins, and creating build logic will be your second nature.
Table of Contents (18 chapters)
Gradle Effective Implementations Guide - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Preface

Gradle is the next generation in build automation. Gradle uses convention-over-configuration to provide good defaults, but it is also flexible to be used 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 discuss Gradle's features with code samples throughout the book. We will also discuss how to write tasks, work with files, and write build scripts using the Groovy DSL. Next, we will discuss how to use Gradle in projects to compile, package, test, check code quality, and deploy applications. Finally we will see how to integrate Gradle with continuous integration servers and development environments (IDEs).

After reading this book, you will know how to use Gradle in your 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 how to install it. We will write our first Gradle script and discuss 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 to define tasks and how to use task dependencies to describe the build logic.

Chapter 3, Working with Gradle Build Scripts, covers more functionalities that we can apply in Gradle scripts. We will discuss how to work with files and directories, apply logging to our build scripts, and use properties to parameterize our build scripts.

Chapter 4, Using Gradle for Java Projects, discusses all about using the Java plugin for Gradle projects. Gradle offers several tasks and configuration convention that makes working with Java project very easy. We see how to customize the configuration for project that cannot follow the conventions.

Chapter 5, Dependency Management, covers the support for dependencies by Gradle. We will discuss how to use configurations to organize dependencies. We will also see how to use repositories with dependencies in our build scripts.

Chapter 6, Testing, Building, and Publishing Artifacts, introduces the support of Gradle to run tests from the build script. We will discuss how to build several artifacts for a project and how to publish the artifacts to a repository so that other developers can reuse our code.

Chapter 7, Multi-project Builds, covers Gradle's support for multi-project builds. With Gradle, we can configure multiple projects that can be related to each other easily. We will also see how Gradle can automatically build related or dependent projects if necessary.

Chapter 8Mixed Languages, explains the Scala and Groovy plugin that is included with Gradle to work with projects that have Scala or Groovy code.

Chapter 9, Maintaining Code Quality, introduces the code quality plugins of Gradle. We will see how to use and configure the plugins to include code analysis in our build process.

Chapter 10, Writing Custom Tasks and Plugins, introduces what we need to do to write our own custom task and plugins. We will see how to decouple the definition and usage of a custom task and plugin in separate source files. We will also discuss how to reuse our custom task and plugin in other projects.

Chapter 11, Gradle in the Enterprise, introduces the support of several continuous integration tools for Gradle. We will discuss how to configure a continuous integration server to automatically invoke our Gradle build scripts.

Chapter 12, IDE Support, looks at how Gradle can generate project files for Eclipse and IntelliJ IDEA. We will also see how the IDEs support Gradle from within the IDE in order to run, for example, tasks and keep track of dependencies defined in Gradle scripts.

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 Toolkit (JDK, 1.6 or higher version), Gradle, and a good text editor. In the first chapter, we will see how to install Gradle on our computer.

Who this book is for

You are working on Java (Scala and Groovy) applications and want to use build automation to automatically compile, package, and deploy your application. 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 find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

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

Any command-line input or output is written as follows:

$ gradle -v
------------------------------------------------------------   
Gradle 2.12
------------------------------------------------------------ 
Build time: 2016-03-14 08:32:03 UTC
Chapter 1
[ 5 ]
 Build number: none
 Revision: b29fbb64ad6b068cb3f05f7e40dc670472129bc0
 Groovy: 2.4.4
 Ant: Apache Ant(TM) version 1.9.3 compiled on
 December23 2013
 JVM: 1.8.0_66 (Oracle Corporation 25.66-b17)
 OS: Mac OS X 10.11.3 x86_64

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "With the Gradle GUI, we have a graphical overview of the tasks in a project and we can execute them by simply clicking on the mouse."

Note

Warnings or important notes appear in a box like this.

Tip

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

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 at www.packtpub.com/authors.

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 files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Gradle-Effective-Implementations-Guide-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could 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 find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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 [email protected] 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

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.