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
Modern Development Environment for C++: Part 2
In Part 1 of this series, I gave a quick overview of each tool in the development environment and how I came to the conclusion that the tool was a good fit. Today I’m going […]
Mock Intl and Date globals in Jest
In Javascript land, mocking the browser global objects can be a bit of a pain for tests. Searching StackOverflow gives plenty of complicated answers. Some suggesting using 3rd party mock libraries. Some that overwrite the […]
Bitbucket Parameterized Pipelines
Introduction I’d like to address how to handle lots of deployment environments withinBitBucket Pipelines. Below I’m presenting two options: Using tags to parameterize builds Using the BitBucket API to pass variables Lots of Environments There […]
AWS Cloud HSM, Docker and NGINX
There is quite a bit of easily searchable content on the security benefits of leveraging a Hardware Security Module to manage cryptographic keys, so I will leave that to the scope of another article. The […]