How to create a .war without the MANIFEST.MF file

(John Murph) #1

I am trying to make a .war file without the MANIFEST.MF file. Actually, no, I’m trying to make a zip that includes the contents of a .war file without the manifest from the war being included. Here is what I am doing:

task myZip(type: Zip) {
   into ('innerwar') {

So, I’m trying to put the contents of the war task into the ‘innerwar’ directory in the zip file. This works great, but I cannot keep the from being put there too.

I’ve tried putting an exclude inside the into {} closure. I’ve tried putting an excludes in the war {} closure. As a matter of fact, this:

war {
   exclude "**"

Leads to everything BUT the being excluded. I’ve tried using manifest = null and metaInf { exclude “**” } in the war closure. Nothing works.

Anyone know how to make this happen?

(Jared Nagle) #2

after reading the source code for ‘Jar’ task (of which ‘War’ extends), It looks like it creates the Manifest regardless

//Snippet from Jar.groovy
Jar() {
        extension = DEFAULT_EXTENSION
        manifest = new DefaultManifest(getServices().get(FileResolver))
        // Add these as separate specs, so they are not affected by the changes to the main spec
        metaInf = rootSpec.addFirst().into('META-INF')
        metaInf.addChild().from {
            MapFileTree manifestSource = new MapFileTree(temporaryDirFactory)
            manifestSource.add('MANIFEST.MF') {OutputStream outstr ->
                Manifest manifest = getManifest() ?: new DefaultManifest(null) // this here doesn't give us any option
                manifest.writeTo(new OutputStreamWriter(outstr))
            return new FileTreeAdapter(manifestSource)
        mainSpec.eachFile { FileCopyDetails details ->
            if (details.path.equalsIgnoreCase('META-INF/MANIFEST.MF')) {

This would explain why ‘war { exclude “**” }’ does not work. Is this desired or does this need to be configurable also?

Correct me if this is not what you need or doesn’t do what you require:

task zippy (type: Zip, dependsOn: war) {
    from files(war.inputs) { FileCollection fc ->
        fc.filter {