我想使用通配符复制目录,但Gradle from
任务的copy
方法不接受通配符。
// this doesn't work
task copyDirectory(type: Copy) {
from "/path/to/folder-*/"
into "/target"
}
// this does
task copyDirectory(type: Copy) {
from "/path/to/folder-1.0/"
into "/target"
}
答案 0 :(得分:7)
只需使用'include'任务属性来指定您需要复制的目录的确切文件,如下所示:
task copyDirectory(type: Copy) {
from "/path/to/"
include 'test-*/'
into "/target"
}
更新:如果您只想复制目录内容,那么您必须单独处理每个文件,如下所示:
task copyDirectory(type: Copy) {
from "/path/to/"
include 'test-*/'
into "/target"
eachFile {
def segments = it.getRelativePath().getSegments() as List
it.setPath(segments.tail().join("/"))
return it
}
includeEmptyDirs = false
}