Repackage jar as bundle


(David Resnick) #1

I’d like to repackage a third party jar as an OSGi bundle.

Right now I have the following, which is based on OSGi uberjar recipe from dexterous (https://gist.github.com/69b563a83914b278e2a3)

apply plugin: 'java'
apply plugin: 'osgi'
  configurations {
 uberJar
}
  dependencies {
    uberJar "bla:bla:ver"
}
  classes {
 doLast {
     // without this, the jar task fails with "java.lang.IllegalArgumentException: A Jar can only accept a valid file or directory:" as underlying cause
  ant.mkdir(dir: "$buildDir/classes/main")
 }
}
  jar {
 configurations.uberJar.each { from zipTree(it) }
    manifest {
        instruction 'Export-Package', 'bla.bla', 'bla.bla.api'
        attributes 'Bundle-Name': 'bla-bundle'
        attributes 'Bundle-Version': '1.0.0'
        instruction 'Bundle-Vendor', 'my company'
        attributes 'Bundle-SymbolicName':'bla.bla'
    }
}

This succeeds in creating a bundle with the contents defined in the uberJar dependency.

The problem is in defining the Export-Package. The actual packages in the bundle are not exported, and the explicit instruction is ignored.

Any suggestions on how I can get this working?

Thanks!