【发布时间】:2014-01-15 14:03:58
【问题描述】:
我正在使用 Gradle build 来编译 Java。
在构建过程中,我获得了成功的构建交付物,但我想添加一些额外的文件,这些文件只是 Gradle build 构建的“.war”文件中存在的一些文件的副本或重命名。
以下代码是我正在使用的。我想做的是:
1. 解压缩 build/tmp/warApplication 文件夹中的 .war 文件
2. 复制/重命名文件,即 oldname-1.2.3 到 newname-1.2.3
3. 将 oldname.war.properties 文件复制/重命名为 newname.war.properties
4. 将 oldname.jar.properties 文件复制/重命名为 newname.jar.properties
5. 对 build/tmp/warApplication 文件夹内的所有数据进行战争,并创建原始 .war 文件(即 projectname.war)
问题:
1. unwar 步骤完成后,我看到在 tmp/warApplication 文件夹下,树中的所有文件都有有效的文件大小。
2. warApplication.doLast - 有效,即它不会给出任何错误消息。
3. 完成所有复制/重命名步骤后,我看到 tmp/warApplication 文件夹树或子树级别下的文件大小现在为 0 字节。
我错过了什么?如何将大小为 X 字节的文件 A 复制到相同 X 字节的文件 B。
// add a few extra files
warApplication.doLast {
def tempWarDirU = new File("${buildDir}/tmp/warApplication")
tempWarDirU.mkdirs()
ant.unwar(src: "${buildDir}/thidsWar/${thidsProjectName}.war",
dest: "${buildDir}/tmp/warApplication")
println ""
println "--- Inside warApplication - last stage ---"
println ""
copy {
from "${buildDir}/tmp/warApplication"
into "${buildDir}/tmp/warApplication"
rename (/([a-z]+)-([0-9]+\.[0-9]+.+)/, 'newname-$2')
}
copy {
from "${buildDir}/tmp/warApplication/WEB-INF/classes"
into "${buildDir}/tmp/warApplication/WEB-INF/classes"
rename (/([a-z]+)\.war\.([a-z]+)/, 'newname.war.$2')
}
copy {
from "${buildDir}/tmp/warApplication/WEB-INF/classes"
into "${buildDir}/tmp/warApplication/WEB-INF/classes"
rename (/([a-z]+)\.jar\.([a-z]+)/, 'newname.jar.$2')
}
ant.jar ( update: "true", destfile: "${buildDir}/thidsWar/${thidsProjectName}_1.war") {
fileset(dir: "${buildDir}/tmp/warApplication",includes: '*/**')
}
println ""
println ""
}
【问题讨论】:
标签: copy gradle byte rename zero