Gradle Bundle Plugin allows you to create OSGI bundles. Its main difference from the Gradle OSGI Plugin is that it uses the bnd tool to generate not only a manifest but a whole jar.
The project is no longer maintained (due to lack of time). You are free to fork it or use any of the existing forks under Apache 2.0 license. If anyone is interested in resurrecting the project and become its maintainer you can email me at dm.artyom@gmail.com.
Plugin is hosted in Maven Central Repository. You can easily add plugin to your build script using following configuration
plugins {
id 'org.dm.bundle' version '0.10.0'
}
Depending on the type of your project you also need to add id 'java'
or
id 'groovy'
, etc.
jar
Generates an OSGI bundle.
When you apply the bundle plugin, Jar
task no longer uses gradle Java plugin to
generate the output but rather delegates this action to the bnd tool. The latter,
however, uses the 'Jar' task customization, such as extension, baseName, etc.
To customise the plugin's behaviour you can either add bnd instructions as attributes of the jar manifest or you can specify them in bundle extension (the latter will take precedence over the former). An example:
jar {
manifest {
attributes 'Implementation-Title': 'Bundle Quickstart', // Will be added to manifest
'Import-Package': '*' // Will be overwritten by the insturctions below
}
}
bundle {
instructions << [
'Bundle-Activator': 'foo.bar.MyBundleActivator',
'Import-Package': 'foo.*',
'-sources': true
]
instruction 'Export-Package', '*' // Specify an individual instruction
instruction '-wab', ''
}
Note that restrictions of the bnd tool hold true, that is for example instruction '-sources': true
will not include groovy or scala sources.
You can enable bnd tracing by setting bundle.trace
to true.
bundle {
trace = true
}
You can make Gradle to fail the build in case of bnd build errors by setting bundle.failOnError
to true.
bundle {
failOnError = true
}
By default transitive dependencies are not included to the classpath passed to Bnd, to include them
includeTransitiveDependencies
needs to be set to true.
bundle {
includeTransitiveDependencies = true
}
This can be done using exclude
property of bundle extension, for example:
bundle {
exclude module: 'guava'
exclude group: 'org.jmock'
}
By default the project properties are passed to Bnd (which means they may end up in the resulting MANIFEST.MF),
this can be prevented by setting passProjectProperties
to false:
bundle {
passProjectProperties = false
}
To enable blueprint support you need to pass the following instruction to Bnd:
bundle {
instruction '-plugin', 'aQute.lib.spring.SpringXMLType'
}
When the Gradle Daemon is enabled for a multi-module project, the plugin may produce a compilation bad class file
error. To get around it compilation needs to be run in a separate process, i. e. the following settings need applying:
subprojects {
...
compileJava {
options.fork = true
}
...
}
The current version of plugin assumes Gradle 2.x is used. The last version that supports Gradle 1.x is 0.5, which can be added to your script as follows
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.dm.gradle:gradle-bundle-plugin:0.5'
}
}
apply plugin: 'bundle'