Book Image

Gradle Effective Implementation Guide

Book Image

Gradle Effective Implementation Guide

Overview of this book

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.
Table of Contents (20 chapters)
Gradle Effective Implementation Guide
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Gradle is the next-generation build automation. Not only does Gradle use convention over configuration 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 files, 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 finally, 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 first 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 define 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 files and directories, apply logging to our build scripts, and use properties to parameterize our build scripts.

Chapter 4, Using Gradle for Java Projects, is all about using the Java plugin for Gradle projects. Gradle offers several tasks and configuration conventions that make working with Java projects very easy. We will see how we can customize the configuration for projects that cannot follow the conventions.

Chapter 5, Dependency Management, covers the support for dependencies by Gradle. We will learn how to use configurations 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 configure 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 configure 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 definition and usage of a custom task and plugin into separate source files. 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 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 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 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 find 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 first build we only have one task, so the command gradle h should work just fine."

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
}

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".

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 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 .

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.

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 all Packt books you have purchased 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.

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 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 find any errata, please report them by visiting http://www.packtpub.com/support, 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 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 http://www.packtpub.com/support.

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.