非常简单的问题,但不知何故不起作用!第一次使用 Gradle 任务是编写一个 gradle 任务,该任务迭代目录中的文件并将时间戳作为文件名的前缀。
我有一个脚本,但是当我使用目标运行 Gradle 时,文件名有时会列出,有时不会。没有对目录进行任何更改!排除是排除之前重命名的文件 - 基本上是正则表达式来检查以数字开头的文件。
这是一个脚本
task renameSqlFiles(type: Copy) {
from "${rootDir}/migration/resources"
into "${rootDir}/migration/resources"
include '**/*.sql'
exclude '^\\d+__.sql'
rename { fileName -> println(fileName)
}
Run Code Online (Sandbox Code Playgroud)
def getDate() {
new Date().format('yyyyMMddHHmmssSSS')
}
task renameForMigration() {
println(" :migrate : renameForMigration")
def files = fileTree(dir: "${rootDir}/migration/resources/sql", includes: ['V*.sql'])
doLast {
files.each { file ->
def newFileName = "${getDate()}__${file.getName()}"
ant.move(file: file, toFile:"${file.parent}/${newFileName}")
sleep(1000)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6463 次 |
| 最近记录: |