I'm packaging a library as an OSGi bundle using maven-bundle-plugin
, which uses BND. I noticed BND generated a very long Export-Package
list, mainly because it includes many packages that are exported by the library itself in the uses
directive of other exported packages.
I (kind of) understand the uses
directive. I presume in this case classes of other packages (listed under uses
) are used in method signatures (therefore imported) by classes in the exported package.
In this sense, I have two questions:
- Is it really necessary to included packages that are exported by the same bundle in the
uses
directive of an exported package? Those packages are not going to be exported by any other bundle; therefore no split packages. - Is this behaviour a sign that the package structure of the library is incorrectly defined? Several classes used by top level packages are often in sub-packages and vice-versa. This is a library being adapted to be an OSGi bundle. The package structure was not designed to be OSGi friendly.
Here's how most exported packages are listed in the MANIFEST
Export-Package: org.lib.annotation;version="10",org.lib.coverage;version="10";
uses:="javax.measure.unit, org.lib.annotation,org.lib.geometry,org.lib.ref,org.
lib.ref.operation,org.ref.util"
From all packages in above uses
list, only javax.measure.unit
is imported from another bundle.
maven-bundle-plugin
configuration:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version>
<Export-Package>org.lib.*;version=${project.version}</Export-Package>
<Import-Package>*</Import-Package>
<_experiments>true</_experiments>
</instructions>
</configuration>
</plugin>