我正在尝试编写Gradle任务,将特定文件从深树复制到平面文件夹中.
task exportProperties << {
copy {
from "."
into "c:/temp/properties"
include "**/src/main/resources/i18n/*.properties"
}
}
Run Code Online (Sandbox Code Playgroud)
这会复制正确的文件,但不会使结构变平,所以我最终得到了原始项目中的每个文件夹,其中大多数都是空的.
task exportProperties << {
copy {
from fileTree(".").files
into "c:/temp/properties"
include "**/src/main/resources/i18n/*.properties"
}
}
Run Code Online (Sandbox Code Playgroud)
这次,它不会复制任何东西.
task exportProperties << {
copy {
from fileTree(".").files
into "c:/temp/properties"
include "*.properties"
}
}
Run Code Online (Sandbox Code Playgroud)
几乎可以工作,除了它只是复制每个*.properties文件,当我只想要特定路径中的文件时.
Jul*_*fin 19
我用类似的方式解决了这个问题:
task exportProperties << {
copy {
into "c:/temp/properties"
include "**/src/main/resources/i18n/*.properties"
// Flatten the hierarchy by setting the path
// of all files to their respective basename
eachFile {
path = name
}
// Flattening the hierarchy leaves empty directories,
// do not copy those
includeEmptyDirs = false
}
}
Run Code Online (Sandbox Code Playgroud)
我让它像这样工作:
task exportProperties << {
copy {
from fileTree(".").include("**/src/main/resources/i18n/*.properties").files
into "c:/temp/properties"
}
}
Run Code Online (Sandbox Code Playgroud)
通过将闭包输入Copy.eachFile方法(包括目标文件路径),可以动态修改复制文件的许多方面:
copy {
from 'source_dir'
into 'dest_dir'
eachFile { details ->
details.setRelativePath new RelativePath(true, details.name)
}
}
Run Code Online (Sandbox Code Playgroud)
这会将所有文件直接复制到指定的目标目录中,尽管它也会复制原始目录结构而不包含文件。
| 归档时间: |
|
| 查看次数: |
7006 次 |
| 最近记录: |