Manifest handling in jar

I’m building a .aar file by pulling artifacts from various other tasks and locations. I have this:

task aar(type: Jar) {
    extension 'aar'
    manifest.from jar.manifest
    from(jar.source) {
        into "/"
    }
    from configurations.runtime {
        into "lib"
    }
}

I have two problems:

  1. There’s an extra manifest created in the root of the archive. It appears identical to the one in META-INF.
  2. If I enable the block to copy files into lib, there is no manifest in META-INF; just the one in the root of the archive.

Clearly there’s something I’m not understanding about manifest handling; can somebody help me out?

Aha! It’s actually stuffing the first manifest in /lib/META-INF, with the second remaining in /. Neither of these is where it’s supposed to be: /META-INF.

The following is not doing what you expect, although its technically valid Groovy syntax which is why you don’t receive an error.

from configurations.runtime {
    into "lib"
}

It should look like so:

from(configurations.runtime) {
    into "lib"
}

In the first example the closure was not being passed as an argument to the from() method, therefore the call to into() was being applied to the root spec, which is why everything was going into a ‘lib’ directory.

Thanks! That’s a simple fix, and I appreciate the explanation.

Now one of the two manifest files is in the correct location; but I still have one in the root of the archive. I can simplify the task to this, and still get double manifests:

task aar(type: Jar) {
    extension 'aar'
    from(jar.source) {
        into "/"
    }
}

If you just want the compiled output of your production code in the AAR then try this:

from sourceSets.main.output

This will simply include all the .class files and resources without also trying to bundle in the other JAR’s manifest.

That did it. Thanks!