Book Image

Gradle Essentials

By : Abhinandan Maheshwari
Book Image

Gradle Essentials

By: Abhinandan Maheshwari

Overview of this book

Gradle is an advanced and modern build automation tool. It inherits the best elements of the past generation of build tools, but it also differs and innovates to bring terseness, elegance, simplicity, and the flexibility to build. Right from installing Gradle and writing your first build file to creating a fully-fledged multi-module project build, this book will guide you through its topics in a step-by-step fashion. You will get your hands dirty with a simple Java project built with Gradle and go on to build web applications that are run with Jetty or Tomcat. We take a unique approach towards explaining the DSL using the Gradle API, which makes the DSL more accessible and intuitive. All in all, this book is a concise guide to help you decipher the Gradle build files, covering the essential topics that are most useful in real-world projects. With every chapter, you will learn a new topic and be able to readily implement your build files.
Table of Contents (17 chapters)
Gradle Essentials
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Tasks


As we have seen so far, a task is a named action that performs some build logic. It's a unit of build work. For example, clean, compile, dist, and so on, are typical build tasks that easily come to our mind if we have to write tasks for our project. Tasks are more or less analogous to Ant's targets.

The simplest way to create a task is as follows:

task someTask

Before we go any further with tasks, let's take a moment to ponder about task creation.

We used the taskName task form of a statement.

If we rewrite it as a task (taskName), it will immediately look like the method call.

The preceding method, as we might have already guessed by now, is available on the project object.

So, we could write one of the following as well:

  • project.task "myTask"

  • project.task("myTask")

Notice that in the later examples we had to pass the task name as a string. The task taskName is a special form where we can use taskName as a literal instead of string. This is done by Groovy AST transformation magic.

The project...