How can I avoid jar manifest configuration repetition in subprojects?

After spending a few days working on Smack’s Ant to Gradle migration, I finally reached a state where I am very happy with the functionality of the resulting build.gradle. :slight_smile: But looking at the file reveals that the jar manifest configuration repeats for 6 of the 7 sub projects, as the following jar configuration block is repeated 6 times:

project(':extensions') {
 jar {
  manifest {
   attributes('Bundle-SymbolicName': project.group + '-' + appendix,
        'Fragment-Host': project.group)
   from sharedManifest
  }
 }
}

Source: https://github.com/Flowdalic/smack/blob/gradle/build.gradle http://bpaste.net/show/179084/

Is there a clean, gradle idiomatic way, to avoid this repetition? Note that one subproject (:core) slightly differs how the manifest is configured.

As a side note: I am unable to use the ‘instruction’ method from the OSGi plugin when creating the manifest. It results in the following error message: “Could not find method instruction() for arguments [Bundle-Version, 3.5.0-SNAPSHOT] on root project ‘smack’.” Being not really an OSGi export, I’m also unsure where the difference is between

attributes('Bundle-SymbolicName': 'Foo')

and

instruction 'Bundle-SymbolicName', 'Foo'

Since I’m planing to squash merge the gradle branch soon back upstream, any further comments and suggestions about improving Smack’s build.gradle are very welcomed.

I was able to solve this with the help of darylteo from #gradle. Here is the code that did the trick:

(subprojects - project(':core'))*.jar {
 manifest {
  attributes('Bundle-SymbolicName': project.group + '-' + appendix,
       'Fragment-Host': project.group)
  from sharedManifest
 }
}