Is there a way to execute a Sync within a function (same as copy method)?
i.e. with copy method we can do:
def myFunc() {
...
copy {
from 'here'
into 'there'
}
...
}
I want to do something like:
def myFunc() {
...
sync {
from 'here'
into 'there'
}
...
}
Thanks!
Gradle doesn’t currently offer a ‘Project.sync()’ method. The current implementation of the ‘Sync’ task does a delete followed by a copy, which you can “reimplement” using the ‘Project.delete()’ and ‘Project.copy’ methods.
Note that methods should only be preferred over tasks when there is a very good reason, as tasks have a number of advantages (up-to-date check, task autowiring, etc.).
Thanks for the reply. 1. I think I’ll go with the sync task because of the advantages you mentioned. 2. You said that the sync task runs delete and then copy. I thought it leaves files that are identical between source and destination in place which is more efficient especially for large files. I have a situation where I need to sync two large folders where most files are the same so I thought using a sync would be faster.
It won’t currently be faster. It may be faster in the future.