Gradle JavaExec Sample with Bundlor

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 {

No surprise: The bundlorRuntime contains all dependencies needed to run the Java executable Bundlor (version 1.1.2.RELEASE in our case):

dependencies {

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 file name it and you are good to go: Run

$ ./gradle bundlor

to generate the OSGi metadata based on your template for the Java library for RabbitMQ.

Show Comments