Karaf Auto-Feature Generating Gradle Plugin

0

I’ve over the last year or so really started to switch my focus from JEE based architecture more toward OSGi based architecture as the deployment model and service modularity of OSGi fits with my recent service layer designs. That, however, is a topic for another day.

OSGi

Now if you know nothing about OSGi that’s ok. For the purposes of this post just understand that a service jar’s dependencies are not bundled with it like in the world of JEE. The dependencies must already exist in the OSGi runtime and are then shared with whatever other jars need them.

As it is in the world of Java, most jars have tons of external dependencies. That being said, each one of those dependencies (and their transitive dependencies) will need deployed to our OSGi runtime for our service to function properly – or at all. I could have Gradle  list out all the dependencies used by the service and then manually deploy them – but as you can imagine that would be tedious and fraught with errors and omissions. I simply won’t do that (I hate doing anything manually more than once). Suffice it to say that I need an automated means of deploying my services into a OSGi runtime, which is in this case Karaf.

Karaf

Karaf has this notion of a feature – which is basically a listing of bundles (and other features) to deploy in order to fulfill some product’s dependencies – which sounds exactly like something I need to do to solve my problem. The issue is that it’s a verbose XML file, and I don’t won’t to have to do a bunch of text manipulation of Gradle’s dependency output in order to generate it. No, what I need is a plugin that interacts with the project build that will automatically do this for me – no muss, no fuss.

I immediately – being a Gradle newb – started scouring the doc’s and API’s of Gradle and determined that I could in fact, using Gradle’s API’s, get a concise list of the resolved runtime dependencies of my project, manipulate them, and generate a proper feature file for deployment into the OSGi runtime that would satisfy my project’s requirements.

This post serves to outline a little of the background of my issue and a proposed solution. The next couple will cover:

  • What is a feature file?
  • Gradle plugin creation
  • The final solution

I would imagine it will take at least two follow-up posts – so stick around, it’s kind of cool 😉

Tags: , ,

Reply