Embedding Transitive Dependencies in OSGI
Asked Answered
A

2

6

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

Albanian answered 7/3, 2017 at 16:19 Comment(4)
Did you get this solved?Mae
If I remember correctly, no. And it was one of the reasons I stopped using OSGIAlbanian
Did you found the issue? I had the same problem here: #58457782. Still looking for a solution.Alchemize
No and I abandoned OSGI because of that, not worth the hassleAlbanian
H
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.

Hers answered 10/3, 2017 at 10:43 Comment(3)
Hello Christian, so you think there is a problem with specifying the exact name of the 3rd-Party library?Albanian
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 thisAlbanian
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.Hers
M
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>
Massachusetts answered 11/8, 2022 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.