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.
Import-Package
instruction, it is auto-generated with all my compile-time dependencies, but not runtime dependencies.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
?
I'm not familiar with the Gradle bnd plugin, but I am familiar with bnd.
The default value of Import-Package
in bnd instruction is *
. The means: match against all of the generated imports. If you specify a single value for Import-Package
then it overrides the *
and becomes the sole import. Therefore your Import-Package
instruction nearly always should end with a catch-all *
in the last position.
Taking a guess at how this would translate to Groovy/Gradle, I suggest the following:
instruction 'Import-Package', 'org.springframework.orm', '*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With