Dec 11, 2014

Copying multiple directories in a single Gradle task with up-to-date checking

Suppose you wanted to copy several directories of Twitter Bootstrap styling and JavaScript, each one into a different destination directory. And you wanted to use Gradle’s up-to-date checking with defined inputs and outputs to only run the task when needed, i.e. when a task input or output changed. Gradle has a built-in Copy task type, but that only supports a single destination directory. Now if you didn’t want to define a separate Gradle task for each directory, how can you copy multiple directories in a single Gradle task?

Maybe the first way you find is to use Gradle’s append syntax to define the task.

But if you try to define task inputs and outputs with the above task type, Gradle will warn you in the console that up-to-date checking wasn’t supported in this task.

Don’t despair, there is a solution! You can use a doLast closure inside the Gradle task to be able to copy multiple directories and still use up-to-date checking. This is what the resulting task might look like with up-to-date checking enabled:

Now you have a single task that will copy multiple directories and will only run when one of those defined inputs or outputs changes!

About the Author

Object Partners profile.

One thought on “Copying multiple directories in a single Gradle task with up-to-date checking

  1. Jesse says:

    How were u able to use ${bowerComponentsDir}? where did you define the variable.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Snowflake CI/CD using Jenkins and Schemachange
CI/CD and Management of Data Warehouses can be a serious challenge. In this blog you will learn how to setup CI/CD for Snowflake using Schemachange, Github, and Jenkins. For access to the code check out […]
How to get your pull requests approved more quickly
TL;DR The fewer reviews necessary, the quicker your PR gets approved. Code reviews serve an essential function on any software codebase. Done right, they help ensure correctness, reliability, and maintainability of code. On many teams, […]
Kafka & Kubernetes: Scaling Consumers
Kafka and Kubernetes (K8s) are a great match. Kafka has knobs to optimize throughput and Kubernetes scales to multiply that throughput. On the consumer side, there are a few ways to improve scalability. Resource & […]
AWS RDS MYSQL Playground
Do you need a reliable database platform to hammer out some new application ideas? Or, maybe you’d like to learn MYSQL in a disposable environment? This Hashicorp Terraform MYSQL RDS Module will build all the […]