Reputation: 8428
I want to synchronize a folder on my drive with another folder that contains a folder named 'logs' that i want to keep. confused? here's a diagram:
C:\
|-- mydir/ # sync this folder
| `-- someotherfiles.txt
`-- anotherDir/ # into this folder
|-- logs/ # but if this exists, leave it there
`-- someotherfiles.txt
Is this possible using the sync task? I can't seem to configure it properly, my latest attempt might allude you to my scenario so here it is (not working):
task syncDevDeployFolder(type: Sync, group: 'dev') {
from currentDeliverablesDir
destinationDir = file(project.properties['dev.deployment.dir'])
into (project.properties['dev.deployment.dir']) {
exclude "logs"
}
}
Upvotes: 2
Views: 2837
Reputation: 2220
At the time of writing, the current version of Gradle is 3.3 and since version 3.1 there is an incubating feature called 'preserve' which can be used to achieve what you want:
See the example from the documentation:
// You can preserve output that already exists in the
// destination directory. Files matching the preserve
// filter will not be deleted.
task sync(type: Sync) {
from 'source'
into 'dest'
preserve {
include 'extraDir/**'
include 'dir1/**'
exclude 'dir1/extra.txt'
}
}
So in your case you could specify it like this:
preserve {
include 'logs/**'
}
Upvotes: 3
Reputation: 9868
You can fallback to ant's sync task. ant
object is available to all gradle build scripts anyways
task antSync << {
ant.sync(todir:"dest/"){
ant.fileset(dir: "source/")
ant.preserveintarget(includes: "logs/")
}
}
Upvotes: 1
Reputation: 123910
Is this possible using the sync task?
No, the Sync
task doesn't currently support this.
Upvotes: 1