I'm building an OSGi jar using Gradle, and I'm having a bit of trouble with the manifest. Here's an excerpt from my build script:
apply plugin: 'java'
apply plugin: 'osgi'
jar {
baseName = 'awesome'
manifest {
name = 'An Awesome Application'
symbolicName = 'com.example.awesome'
// instruction 'Import-Package', 'org.springframework.orm'
}
}
Using the above, Gradle detects my dependencies and adds an Import-Package
with all my compile-time dependencies. But say my application has a runtime dependency on org.springframework.orm
as well, how do I tell Gradle to include that as an argument in Import-Package
?
With the commented row above uncommented, the generated Import-Package
instruction specifies only org.springframework.orm
. This confuses me, since the Gradle documentation for OsgiManifest states
OsgiManifest instruction(String name, String... values)
Adds arguments to an instruction. If the instruction does not exists, it is created. If it does exists, the arguments are appended to the existing arguments.
This doesn't seem to apply for the auto-detected Import-Package
arguments, however. If I specify instruction 'Import-Package', 'my.dependency.1'
and so on, and print jar.manifest.instructions
in between, I can see how they are added in sequence, and they all appear in the generated manifest, but it seems that Gradle's OSGi plugin does not add the auto-detected arguments if Import-Package
is manually specified.
TL;DR:
- If I do not manually specify the
Import-Package
instruction, it is auto-generated with all my compile-time dependencies, but not runtime dependencies. - If I do
manifest { instruction 'Import-Package', 'org.springframework.orm' }
, then the compile-time dependencies are not automatically included.
How can I tell Gradle my runtime dependencies so they can be added to Import-Package
?