This post will cover the differences between the existing options for building OSGi bundles using Maven and provide some useful examples. Historically, there has only been one maven plugin option for building OSGi bundles, the Apache Felix maven-bundle-plugin; however, another plugin option has recently become available (see announcement), the bnd-maven-plugin. Both plugins rely on bnd (often referred to as the swiss army knife of OSGi) under the hood, but they diverge a bit in the details.
Differences between maven-bundle-plugin and bnd-maven-plugin
Maven LifeCycle Differences
The first notable difference between the two plugins is in how they hook into the Maven build lifecycle. The felix maven-bundle-plugin extends the default maven lifecylcle with its own “lifecycle enhancement”, and enables a custom packaging type of “bundle”. Its noteworthy that it is possible to avoid the use of the custom packaging type (see here), but this is the expected default.
The bnd-maven-plugin is designed instead to hook into the default Maven “process-classes” lifecycle and does not require any custom packaging type. This was a conscious decision on the part of the implementors and was meant to mitigate some of the issues that can be caused by the use of the custom “bundle” packaging type (e.g. interoperability with other Maven plugins).
BND Configuration format (pom vs bnd)
The second major difference between the two plugins is in how bnd configuration is expected to be passed to bnd. The felix maven-bundle-plugin is typical of most Maven plugins in accepting its configuration through the pom.xml.
Example:
The bnd-maven-plugin allows the options to either use an external bnd file, or embed bnd directives directly into the plugin configuration of the pom.xml.
Example of embedding bnd content in pom.xml:
This example configuration will parse org.osgi.annotation.versioning.Version annotations on package-info.java classes to simplify management of package versioning info.
BND Defaults
The third significant difference between the two plugins is in the details of the bnd configuration defaults.
Export-Package/Private-Package (This is the most significant functional difference between the defaults)
Bundle-Description
Bundle-License
Bundle-Vendor
Example Projects
For both examples, we will reuse the hello-world SCR compoment java code. The goal will be to show how to package up the very same code using each plugin.
For the source, you can checkout the parent project code from github.
bnd-maven-plugin project
Tree View
bnd file (Optional)
A bnd file by the name of “bnd.bnd” can be added to the root directory if custom bnd directives are required for your project; however, in this instance we do not require any configuration since SCR annotations are now processed by default by bnd.
pom.xml
MANIFEST.MF
Felix maven-bundle-plugin project
Tree View
pom.xml
MANIFEST.MF
Subscribe Now
Subscribe to our newsletter for a round-up of the week's most popular articles.