我想将驱动器上的一个文件夹与另一个包含我想要保留的名为“logs”的文件夹的文件夹同步。使困惑?这是一个图表:
C:\
|-- mydir/ # sync this folder
| `-- someotherfiles.txt
`-- anotherDir/ # into this folder
|-- logs/ # but if this exists, leave it there
`-- someotherfiles.txt
使用同步任务可以实现这一点吗?我似乎无法正确配置它,我最近的尝试可能会暗示您我的场景,所以这里是(不起作用):
task syncDevDeployFolder(type: Sync, group: 'dev') {
from currentDeliverablesDir
destinationDir = file(project.properties['dev.deployment.dir'])
into (project.properties['dev.deployment.dir']) {
exclude "logs"
}
}
在撰写本文时,Gradle 的当前版本是 3.3,自 3.1 版本以来,有一个名为“preserve”的孵化功能,可用于实现您想要的功能:
请参阅以下示例文档 https://docs.gradle.org/3.3/javadoc/org/gradle/api/tasks/Sync.html:
// 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'
}
}
因此,在您的情况下,您可以这样指定:
preserve {
include 'logs/**'
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)