Bundlor is a Java tool to create OSGi metadata. These days I investigated how to integrate Bundlor in a Gradle build. After some investigation I created a bundlor task of type JavaExec:
task bundlor(type: JavaExec, dependsOn: createBuildDir) {
classpath = configurations.bundlorRuntime
main = 'org.eclipse.virgo.bundlor.commandline.Bundlor'
args '-D', "version=${artifactVersion}"
args '-i', "${->configurations.sourceBundle[0]}" // lazy GString to resolve the configuration at runtime
args '-m', "${artifactName}.mf"
args '-o', outputFile
}
Let's step back and start with the two configuratinos bundlorRuntime
and sourceBundle
:
configurations {
bundlorRuntime
sourceBundle
}
No surprise: The bundlorRuntime
contains all dependencies needed to run the Java executable Bundlor (version 1.1.2.RELEASE in our case):
dependencies {
bundlorRuntime('org.eclipse.virgo.bundlor:org.eclipse.virgo.bundlor.commandline:1.1.2.RELEASE')
bundlorRuntime('org.eclipse.virgo.bundlor:org.eclipse.virgo.bundlor:1.1.2.RELEASE')
bundlorRuntime('org.eclipse.virgo.bundlor:org.eclipse.virgo.bundlor.blint:1.1.2.RELEASE')
}
More important the sourceBundle
defines the coordinates of a non OSGi bundle to create the metadata for. In our example this is the RabbitMQ AMQP client:
dependencies {
sourceBundle 'com.rabbitmq:amqp-client:3.5.5'
}
Create a template.mf
file name it com.rabbitmq.amqp.client.mf
and you are good to go: Run
$ ./gradle bundlor
to generate the OSGi metadata based on your template for the Java library for RabbitMQ.