Chapter 25. The OSGi Plugin

The Gradle OSGi plugin enables the generation of an OSGi manifest. This OSGi manifest is automatically added to all the JAR files produced by the project. This plugin makes heavy use of Peter Kriens BND tool.

25.1. Tasks

TBD

25.2. Project layout

TBD

25.3. Dependency management

TBD

25.4. Convention properties

The OSGi plugin adds an osgi property to every jar task. This osgi property points to an instance of OsgiManifest . Via the OsgiManifest object you can control the generation of the OSGi Manifest of the respective jar. The OSGi plugin assign default values to the OsgiManifest object.

Table 25.1. OSGi properties

Task Property Convention Property
classesDir project.classesDir
version project.version
name project.archivesBaseName
symbolicName transformation of the name and the group to produce a valid OSGi symbolic name
classpath project.dependencies.resolve('runtime')

The classes in the classes dir are analyzed regarding there package dependencies and the packages they expose. Based on this the Import-Package and the Export-Package values of the OSGi Manifest are calculated. If the classpath contains jars with an OSGi bundle, the bundle information is used to specify version information for the Import-Package value. Beside the explicit properties of the OsgiManifest object you can add instructions.

Example 25.1. Configuration of OSGi MANIFEST.MF file

build.gradle

configure(jar.osgi) {
    name = 'overwrittenSpecialOsgiName'
    instruction 'Private-Package',
            'org.mycomp.package1',
            'org.mycomp.package2'
    instruction 'Bundle-Vendor', 'MyCompany'
    instruction 'Bundle-Description', 'Platform2: Metrics 2 Measures Framework'
    instruction 'Bundle-DocURL', 'http://www.mycompany.com'
}

The first argument of the instruction call is the key of the property. The other arguments form the value. They are joined by Gradle with the , separator. To learn more about the available instructions have a look at the BND tool.