Book Image

Mastering Gradle

Book Image

Mastering Gradle

Overview of this book

Table of Contents (17 chapters)
Mastering Gradle
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Gradle's in-built tasks


For day-to-day build-related activities, Gradle provides a variety of tasks. We will take a look at some of Gradle's in-built tasks.

The Copy Task

This task is used to copy file(s) or directories from one location to the other:

task copyTask(type: Copy) {
  from "."
  into "abc"
  include('employees.xml')
}

In copyTask, we have configured the from location and into location, and have also added the condition to include only employees.xml.

The Rename Task

This task is an extended version of the copy task, which is used to rename files or directories:

task copyWithRename(type: Copy) {
  from "."
  into "dir1"
  include('employees.xml')
  rename { String fileName ->
  fileName.replace("employees", "abc")
  }
}

In the copyWithRename task, an additional rename closure was added.

The Zip task

This task is used to zip a group of file(s) or directories and copy the zip to the destination directory:

task zipTask(type: Zip) {
  File destDir = file("dest")
  archiveName "sample.zip...