title: OSGi and Transitive Dependencies
body: <p>I’m using Felix Framework for my OSGi project, but I’ve came across a severe problem concerning third party dependencies.</p>
  
  <p>I’m using eclipse and maven-bundle-plugin to generate my bundles from the sources and the MANIFEST.MF from the POM.XML file. So far so good. however when I have some third party dependency in my bundle, I find myself looking for an infinite list of JARs, which usually are not bundles, and putting them in my /bundle Felix directory until no more dependencies are missing.</p>
  
  <p>I call this process “Downloading the Internet for my OSGi application to work”.</p>
  
  <p>What am I doing wrong? Sure I must be doing something very wrong, because I can’t imagine anyone having a bundle A that depends on B, which then depends on C and D, and then those two will depend on several others and so on… to go look for ALL those dependencies manually using google or maven central! That's insane!</p>
  
  <p>What is the correct way to automate this? I would love to have one of the two solutions:</p>
  
  <p>1) Be able to create a massive JAR file with all of its dependencies embedded, but exporting only the packages I want, and, of corse, not importing any package.</p>
  
  <p>2) (My preferred solution) Having a way to get all my dependencies into individual JAR files that I can simply paste into the /bundle directory.</p>
  
  <p>3) (Even more preferred) Having a way to use third party JARs without downloading 8GB of dependencies to my project.</p>
  
  <p>I have found tools that do me this, <strong>but just for direct (1st degree) dependencies</strong>, leaving transitive dependencies for me to solve manually.</p>
  
  <p>This problem is critical. The lack of such a tool hampers the usage of OSGi. I’ve searched and searched and searched, I’ve came across all the 101 solutions such as PAX, bndtools, and friends, but it seems that they <strong>do not</strong> solve this issue…</p>
  
  <p>Please help me. <strong>Please provide a living example if you can, people like me around the world will benefit from the solution to this problem.</strong></p>
  
  <p>Thanks!</p>
  
  <h2>-</h2>
  
  <h2>-</h2>
  
  <p><strong>Edit:</strong> I am attaching a example project where I'm trying to use JScience but the resulting JAR bundle keeps asking me for new Imports, i.e., it is not self-contained.</p>
  
  <p>Link to the example: <a href="https://www.dropbox.com/s/svo3nu3vawvv2xn/RequireJscienceExample.zip?dl=0">https://www.dropbox.com/s/svo3nu3vawvv2xn/RequireJscienceExample.zip?dl=0</a></p>
  
  <p>I usually try to convert 3rd party JARs into bundles using Eclipse, but they always have to Import packages that I do not have, so it is an endless situation as you have stated.</p>
  
  <p>I could not find any documentation concerning the tag Conditional_Package for maven-bundle-plugin. However related searches show me the inline option that I have tried before without success.</p>
  
  <p>I created a basic project where I have one class using JScience library, and in its POM.XML I have the following:</p>
  
  <pre><code>&lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.7&lt;/version&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
                  &lt;configuration&gt;
                      &lt;instructions&gt;
                          &lt;Bundle-SymbolicName&gt;${project.artifactId};singleton:=true
                          &lt;/Bundle-SymbolicName&gt;
                          &lt;Bundle-Version&gt;${project.version}&lt;/Bundle-Version&gt;
                          &lt;Export-Package&gt;shared.properties.api, shared.properties.base
                          &lt;/Export-Package&gt;
                          &lt;Embed-Dependency&gt;!org.osgi.*;scope=compile|runtime;inline=true&lt;/Embed-Dependency&gt;
                          &lt;Embed-Transitive&gt;true&lt;/Embed-Transitive&gt;
                      &lt;/instructions&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
  &lt;/plugins&gt;
  </code></pre>
  
  <p>I am saying maven to inline all packages which are not from the osgi framework itself. And Looking at the resulting JAR it looks pretty good, I now have embedded only packages instead of entire JARs (however it looks to me that I didn’t need all those inlined packages since I’m using just two of them). Moreover, if I open the MANIFEST.MF file I can see this problematic line:</p>
  
  <pre><code>Manifest-Version: 1.0
  Bnd-LastModified: 1414164534170
  Build-Jdk: 1.6.0_65
  Built-By: Pedro
  Bundle-ManifestVersion: 2
  Bundle-Name: RequireJscienceExample
  Bundle-SymbolicName: RequireJscienceExample;singleton:=true
  Bundle-Version: 0.0.1.SNAPSHOT
  Created-By: Apache Maven Bundle Plugin
  Embed-Dependency: !org.osgi.*;scope=compile|runtime;inline=true
  Embed-Transitive: true
  Import-Package: org.joda.convert,org.xml.sax &lt;------ Problem...
  Tool: Bnd-1.50.0
  </code></pre>
  
  <p>saying that I’m missing org.joda.convert and org.xml.sax.</p>
  
  <p>What amazes me is that we are talking about a library (JScience) that states being OSGi compatible: <a href="http://jscience.org/">http://jscience.org/</a></p>
  
  <p>What am I missing? I really cannot afford not using JScience. And I have rejected several 3rd party libraries before, that would spare me development time, because of these OSGi 3rd party integration difficulties.</p>