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.
Project Status
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 [email protected].
Installation
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.
Tasks
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.
Customization
Instructions
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.
Bnd tracing
You can enable bnd tracing by setting bundle.trace to true.
bundle {
trace =true
}
Failing build in case of bnd build errors
You can make Gradle to fail the build in case of bnd build errors by setting bundle.failOnError to true.
bundle {
failOnError =true
}
Passing transitive dependencies to Bnd
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
}
Exclusion of dependencies from the classpath passed to Bnd
This can be done using exclude property of bundle extension, for example:
Exclusion of project properties from the set of instructions passed to Bnd
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
}
Blueprint support
To enable blueprint support you need to pass the following instruction to Bnd:
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:
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
请发表评论