質問

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 ""
}
役に立ちましたか?

解決 2

Had to mention the "include" section. without that, it'was copying all files into 0 bytes in the tree.

   copy {
      from "${buildDir}/tmp/warApplication"
      into "${buildDir}/tmp/warApplication"
      include "${thidsProjectName}-$project.version"
      rename (/([a-z]+)-([0-9]+\.[0-9]+.+)/, 'newname-$2')
   }
   copy {
      from "${buildDir}/tmp/warApplication/WEB-INF/classes"
      into "${buildDir}/tmp/warApplication/WEB-INF/classes"
      include "${thidsProjectName}.war.properties"
      rename (/([a-z]+)\.war\.([a-z]+)/, 'newname.war.$2')
   }
   copy {
      from "${buildDir}/tmp/warApplication/WEB-INF/classes"
      into "${buildDir}/tmp/warApplication/WEB-INF/classes"
      include "${thidsProjectName}.jar.properties"
      rename (/([a-z]+)\.jar\.([a-z]+)/, 'newname.jar.$2')
   }

他のヒント

An easier solution would be, thanks to Pete N.

task renABCToXYZ {
    doLast {
        file("ABC").renameTo(file("XYZ"))
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top