2

Are there plans to support "Require-Bundle" in maven-bundle-plugin, even if its not the recommended OSGi way. There are situations where it makes sense to use "Require-Bundle", for example to merge split packages.

user1654885
  • 131
  • 1
  • 3
  • 8

2 Answers2

5

Require-Bundle is supported by the bundle-plugin, just like all OSGi headers plus any other arbitrary headers that you want to use. Just write them in the XML:

<Require-Bundle>
    org.example.foo; bundle-version=3.0,
    org.example.bar; bundle-version=1.0
</Require-Bundle>
<My-Extension-Header>
    blah blah blah
</My-Extension-Header>
Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
0

You can specify Require-Bundle MANIFEST header in the instructions. E.g.:

<instructions>
    <Require-Bundle>a.b.c</Require-Bundle>
</instructions>

However, version range of the required bundle will not be appended automatically, so you have to specify it manually if that is necessary.

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • But the dependencies are not resolved automatically, AS it is down with the import package pattern *. Right? – user1654885 Dec 22 '14 at 13:17
  • In case of split packages, the order of bundles in Require-Bundle matters. Bnd cannot decide which Bundle should be first in the order automatilly. Also, bnd should analyze each method call to decide if it is enough to import a package as it is used only from one bundle or the usage of Require-Bundle is necessary. As it is too complex question, where some answers cannot be provided automatically (like the order of the bundles), you must maintain this HEADER manually. However, the best is if you completely avoid the usage of Require-Bundle. – Balazs Zsoldos Dec 22 '14 at 13:24
  • Thanks for your answer. But isnt the Situation the same with import? The order matters even more and you actually cant merge packages at all?! I also dont understand why the order matters for require-bundle – user1654885 Dec 22 '14 at 13:27
  • Ordering does not matter at Import-Package as the same package (with different version) cannot be imported twice. With Require-Bundle, the same package can be imported from multiple bundles, and those packages can contain the same classes. In that case, the order matters when a class is searched. In case you have dependencies and multiple dependencies contain the same package, bnd takes the first one and generated Import-Package based on it. If it wanted to generate Require-Bundle, it would not know if Require-Bundle should be used or Import-Package in this case. – Balazs Zsoldos Dec 22 '14 at 13:42