I'm using Gradle build to compile Java.
During the build, I get successful build deliverables BUT I want to add some extra files which are just the copy or rename of some files which exist within the built ".war" file by Gradle build.
The following code is what I'm using. What I'm trying to do is:
1. unwar a .war file in a build/tmp/warApplication folder
2. copy/rename a file i.e. oldname-1.2.3 to newname-1.2.3
3. copy/rename oldname.war.properties file to newname.war.properties
4. copy/rename oldname.jar.properties file to newname.jar.properties
5. war all data inside build/tmp/warApplication folder and create original .war file (which is projectname.war)
Issue:
1. After unwar step is complete, I see under tmp/warApplication folder, all files in the tree have valid file size.
2. warApplication.doLast - works i.e. it doesn't give any error mesg.
3. Once all copy/rename steps are complete, I see the file size under tmp/warApplication folder tree or subtree level is now 0 bytes in size.
WHAT am I missing? How can I copy a file A of size X bytes to file B of same X bytes.
// 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 ""
}
With the Gradle copy task we can define renaming rules for the files that are copied. We use the rename() method of the copy task to define the naming rules. We can use a closure where the filename is the argument of the closure. The name we return from the closure is the new name of copied file.
A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
buildscript: This block is used to configure the repositories and dependencies for Gradle. Note: Don't include dependencies here. ( those will be included in the module-level build.gradle) dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project. Java.
An easier solution would be, thanks to Pete N.
task renABCToXYZ {
doLast {
file("ABC").renameTo(file("XYZ"))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With