我不明白为什么我不能将文件复制到projectDir
. 该目录在执行期间是否被阻止?例如:
这有效:
task metadataFile(type: Copy) {
from projectDir
into 'aaa' // projectDir+"/aaa"
include 'myfile.txt'
rename 'myfile.txt', 'myfile.new.txt'
}
但事实并非如此(返回 IOException: The process cannot access the file because another process has locked a part of the file):
task metadataFile(type: Copy) {
from projectDir
into projectDir
include 'myfile.txt'
rename 'myfile.txt', 'myfile.new.txt'
}
我是否需要先将文件复制到临时目录然后将其移动到projectDir
?ant.copy
可以用来代替 gradle 复制任务,但这不是解决方案。