Install & uninstall set of files into a war

I want to take a set of files (or a jar) and add them to an existing war. That may be fairly straight forward but I would also like to: 1) Write an audit log into the war with a list of the files I added or updated. 2) Read the audit log from the war at a later date so that I can uninstall those changes.

Any suggestions on how to go about this?

Where do the files to add and the war come from?

The files come from a zip or jar file (which is a custom dependency). So I can wrap it in a zipTree().

I’m wondering what approach to use to “record” the changes in log file which can be used to uninstall the changes later.

Something like this:

task additionsManifest {
  destination = file("$buildDir/manifest.txt")
  source = zipTree(someJarFile)
    // for incremental build
  inputs.files { source }
  outputs.file { destination }
    doLast {
    destination.withPrintWriter { writer ->
      source.files.each { file ->
  war {
  from additionsManifest
  from additionsManifest.source
  task extractAdditionsManifest(type: Copy) {
  dependsOn war
      // added properties to remove duplication
  manifestFileName = "manifest.txt"
  destination = file("$buildDir/manifest")
  manifestFile file("$destination/$manifestFileName")
      from zipTree(war.archivePath)
  include manifestFileName
  into destination
  task extractedWar(type: Copy) {
  dependsOn extractAdditionsManifest
  from war
  doFirst {
    toExclude = extractAdditionsManifest.manifestFile.readLines()
      eachFile { FileCopyDetails file ->
    if ( in toExclude) {

That’s untested and probably not exactly what you want, but hopefully gives you some ideas on how to start.

Thanks Luke, I’ll give it go.

I’ve decided to extract both the source zip and destination war to working directories. Essentially, I want to do a “diff” between the 2 directories. If a source file is new then its an “addition”, if it exists then I’ll “update” it. I see Gradle has a “sync” task but I’m guessing no “diff”.

right, you’d have to roll your own.