5

I have an OSGI bundle that has a dependency on a 3rd Party library, I don't want to deploy that library in the container, I'd rather embed it in my bundle.

Of course, that library has its own dependencies, I want to embed them as well.

I'm using the Maven Bundle Plugin :

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
   <configuration>
     <instructions>
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
        <Bundle-Description>${project.description}</Bundle-Description>
        <Bundle-Vendor>${bundle.vendor}</Bundle-Vendor>
        <Meta-Persistence>...</Meta-Persistence>
        <Export-Package>...</Export-Package>
        <Import-Package>...</Import-Package>
        <Embed-Dependency>3rd-Party</Embed-Dependency>                      
        <Embed-Transitive>true</Embed-Transitive>
      </instructions>
    </configuration>
</plugin>

As a result, 3rd-Party is embedded in the resulting bundle, but NOT its transitive dependencies, as if <Embed-Transitive>true</Embed-Transitive> doesn't have any effect.

So I have some questions

  • Is this the correct way to embed a 3rd party library in a transitive way ?
  • Does this take care of the generated Manifest file (not importing packages that belong to the 3rd party library and its dependencies) ?

Thank you

isco
  • 350
  • 4
  • 15

2 Answers2

1

About Embed-Dependency: If you take a look at the felix docs they always use a scope like: ;scope=compile|runtime.

Maybe the names of the dependent bundles must also fit the regex given. If you want to embed most of the jars and only omit a few than maybe you can embed * and then exclude some with !.

About the Manifest: The maven bundle plugin should take care of adapting the imports to your embedded packages. So there should not be imports for packages that are embedded.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Hello Christian, so you think there is a problem with specifying the exact name of the 3rd-Party library? – isco Mar 14 '17 at 08:45
  • as for the imports for packages that are embedded, the list of imported packages grows very fast when I embed dependencies, I think the plugin doesn't take care of this – isco Mar 14 '17 at 11:19
  • A big problem with many libraries is that they use a lot of optional dependencies. If you simply embed such a library then you also get the optional deps. Such a tree can grow very fast. If this is the case for you and you know you do not need some of the optional deps then you can try to exclude them in maven. – Christian Schneider Apr 06 '17 at 05:47
1

For anyone coming here for the same question: it looks like the latest versions of plugin have it fixed.

I'm using 4.2.1 version.

The config that works for me (including embedding all of the needed dependencies and their transitive ones too):

<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
GullerYA
  • 1,320
  • 14
  • 27