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
Rockstar Development
This originally appeared on Marty Henderson’s personal blog Or, how to use Gitpod and GitLab so that no one else has to care about your questionable coding language choices. A true rockstar has a good […]
Testing a Quarkus Kafka Application
Quarkus, a “Kubernetes Native Java stack,” enables lighter Java applications with faster startup times. In a recent post, I talked about scaling Kafka consumers in Kubernetes. Quarkus applications fit right into this picture because they […]
Gitpod and Hringvegurinn
Iceland Ever seen an advertisement for visiting Iceland? Have you noticed that they all mention Hringvegurinn or the Ring Road, as a good tour? (If you haven’t seen a tour ad for Iceland, Steindi Jr […]
Tacos and Steak, an Istio story
This post originally appear on Marty Henderson’s personal blog A brief history In the before times of 2017, Varun Talwar and Louis Ryan sat under a forgotten waterfall at the edge of the world and […]