# Using war copySpec for ant.copy task

**URL:** <https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711>\
**Category:** Help/Discuss\
**Created:** [August 12, 2017, 2:34pm UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711 "2017-08-12T14:34:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bungrudi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bungrudi/32/6373_2.png) [@bungrudi](https://discuss.gradle.org/u/bungrudi)\
**Post date:** [August 12, 2017, 2:34pm UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/1 "2017-08-12T14:34:12Z")

</div>

I found out that when doing exploded war construction for development purpose, doing ant.copy is a lot faster than using copy { into ‘dir’; with war }.  
The problem with gradle copy is that it isnt really doing the copy incrementally (while the task itself have up-to-date checking); at least that is what I understand from here [https://github.com/gradle/gradle/issues/1643](https://github.com/gradle/gradle/issues/1643) .  
On the other hand, Ant’s Copy task only copy ‘newer’ file.

The question: is there an easy way to reuse war copySpec to ant.copy() ?

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [August 13, 2017, 8:24am UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/2 "2017-08-13T08:24:10Z")

</div>

I think you want [Sync](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Sync.html) rather than `Copy`

---

<div class="post-metadata">

**Author:** ![bungrudi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bungrudi/32/6373_2.png) [@bungrudi](https://discuss.gradle.org/u/bungrudi)\
**Post date:** [August 13, 2017, 8:26am UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/3 "2017-08-13T08:26:33Z")

</div>

I tried both Copy and Sync.  
Both are painfully slow; at least in Windows 10 needing to copy/sync thousand of small files.  
Ant’s copy is a lot faster since it has timestamp checking; only newer files are being copied.  
As far as I know this method of copying is not yet supported in Gradle.

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [August 13, 2017, 9:16am UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/4 "2017-08-13T09:16:45Z")

</div>

You could likely implement this via [eachFile { … }](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/AbstractCopyTask.html#eachFile(org.gradle.api.Action)) and `FileCopyDetails.exclude()`

---

<div class="post-metadata">

**Author:** ![bungrudi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bungrudi/32/6373_2.png) [@bungrudi](https://discuss.gradle.org/u/bungrudi)\
**Post date:** [August 20, 2017, 5:12am UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/5 "2017-08-20T05:12:50Z")

</div>

Sounds like a good idea; I assume this way I can do the timestamp checking myself and manually copy where applicable.  
Will try this out.

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [August 20, 2017, 5:50am UTC](https://discuss.gradle.org/t/using-war-copyspec-for-ant-copy-task/23711/6 "2017-08-20T05:50:53Z")

</div>

Sort of…

You’d be adding an extra action to a `Copy` task which would `FileCopyDetails.exclude()` any files that don’t pass your timestamp check

No manual copy

See [the javadoc](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/AbstractCopyTask.html#eachFile(org.gradle.api.Action))

> Adds an action to be applied to each file as it is about to be copied into its destination. The action can change the destination path of the file, filter the contents of the file, or exclude the file from the result entirely. Actions are executed in the order added, and are inherited from the parent spec.
