0

I am getting the following error when I try to start one bundle

Chain 1:
  foo.bar.fizz.core.rest.impl [foo.bar.fizz.core.rest.impl [208](R 208.0)]
    import: (&(osgi.wiring.package=javax.annotation)(version>=1.2.0)(!(version>=2.0.0)))
     |
    export: osgi.wiring.package: javax.annotation
  org.apache.felix.framework [org.apache.felix.framework [0](R 0)]

Chain 2:
  foo.bar.fizz.core.rest.impl [foo.bar.fizz.core.rest.impl [208](R 208.0)]
    import: (&(osgi.wiring.package=foo.bar.fizz.cdac.tableobject.api)(version>=8.60.0)(!(version>=9.0.0)))
     |
    export: osgi.wiring.package=foo.bar.fizz.cdac.tableobject.api; uses:=com.google.common.collect
  foo.bar.fizz.cdac.tableobject [foo.bar.fizz.cdac.tableobject [196](R 196.0)]
    import: (&(osgi.wiring.package=com.google.common.collect)(version>=16.0.0)(!(version>=17.0.0)))
     |
    export: osgi.wiring.package=com.google.common.collect; uses:=javax.annotation
  com.google.guava [com.google.guava [29](R 29.0)]
    import: (osgi.wiring.package=javax.annotation)
     |
    export: osgi.wiring.package: javax.annotation
  org.jsr-305 [org.jsr-305 [28](R 28.0)] Unresolved requirements: [[foo.bar.fizz.core.rest.impl [208](R 208.0)] osgi.wiring.package; (&(osgi.wiring.package=foo.bar.fizz.cdac.tableobject.api)(version>=8.60.0)(!(version>=9.0.0)))]

I understand why the error comes (because one dependency is coming from two flows and osgi is confused between the two). However, I don't get how to avoid this since one flow is "org.apache.felix' which starts with 0 start level and I can't seem to alter that.

Here are more logs for the bundle:tree-show


foo.bar.fizz.cdac.tableobject [197]
+- foo.bar.fizz.cdac.api [194]
|  +- foo.cil.cdac.cil-cdac-common-api [133]
|  +- avro [292]
|  |  +- org.xerial.snappy.snappy-java [329]
|  |  +- jackson-core-asl [314]
|  |  +- jackson-mapper-asl [315]
|  |  |  +- jackson-core-asl [314]
|  |  +- org.ops4j.pax.logging.pax-logging-api [6]
|  |  |  +- org.apache.karaf.services.eventadmin [3]
|  |  |     +- org.apache.felix.metatype [2]
|  |  |     +- org.apache.felix.configadmin [9]
|  |  |        +- org.apache.felix.coordinator [8]
|  |  +- org.apache.commons.compress [293]
|  |  |  +- org.tukaani.xz [328]
|  |  +- com.thoughtworks.paranamer [257]
|  |     +- org.glassfish.hk2.external.jakarta.inject [92]
|  +- com.google.gson [252]
|  +- foo.bar.common.datatypes.date [224]
|  |  +- joda-time [287]
|  +- foo.cil.client.service [136]
|  |  +- avro [292]
|  |  +- org.apache.servicemix.bundles.lucene [309]
|  |  +- org.apache.servicemix.bundles.lucene-queryparser [307]
|  |     +- org.apache.servicemix.bundles.lucene [309]
|  |     +- org.apache.servicemix.bundles.lucene-sandbox [308]
|  |     |  +- org.apache.servicemix.bundles.lucene [309]
|  |     |  +- org.apache.servicemix.bundles.jakarta-regexp [303]
|  |     +- org.apache.servicemix.bundles.lucene-queries [306]
|  |        +- org.apache.servicemix.bundles.lucene [309]
|  +- org.ops4j.pax.logging.pax-logging-api [6]
|  +- foo.bar.fizz.businessentity [193]
|     +- foo.bar.common.datatypes.date [224]
+- foo.bar.common.datatypes.date [224]
+- com.fasterxml.jackson.core.jackson-databind [242]
|  +- com.fasterxml.jackson.core.jackson-annotations [238]
|  +- com.fasterxml.jackson.core.jackson-core [240]
+- org.ops4j.pax.logging.pax-logging-api [6]
+- foo.bar.fizz.businessentity [193]
+- com.google.guava [30] <- START LEVEL
   +- org.jsr-305 [29]
   +- org.glassfish.hk2.external.jakarta.inject [92]
karaf@root()>                                                

What have I tried and did not work ?

  • I tried blacklisting the bundle but nothing really happened.
  • I tried excluding the dependency that is causing this problem (jsr-305) but that did not work either.
  • Start level changed.

Please suggest something that can solve this or at least point me in the right direction.

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42

2 Answers2

0

The solution I opted for is to change my osgi implementation from Felix to Equinox.

Apparently, karaf, by default, uses felix but you can override it using custom.properties file and add the following line to it

Dir structure

assembly
 etc
  custom.properties

File content

karaf.framework=equinox

Explanation

Felix provides its own javax.annotation which I couldn't exclude so I opted for this solution.

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
0

Thing is, do you really need to install org.jsr-305 in chain 2 if the packages is already exported by the felix framework in chain 1 ?

Changing from Felix to Equinox would solve the problem if Equinox doesn't export that package at first, but note that Felix is also quite faster than Equinox to boot (multi-thread resolution, etc)

Jonathan Schoreels
  • 1,660
  • 1
  • 12
  • 20
  • I agree what you just told about Felix but I just couldn't get rid of the jsr. It seems to be coming in from the guava dependency from a project. For some reason, I couldn't modify that project pom. – cafebabe1991 Oct 01 '20 at 19:21
  • Also, I think, I need to use exclusions with all my dependencies so I don't get such surprises. This way Ill be able to control them and then probably switch to felix. – cafebabe1991 Oct 01 '20 at 19:22
  • Hmmm if you Uninstall the jsr bundle, guava should be fine since Felix is still exporting it, and everyone would target the jsr packages of the framework – Jonathan Schoreels Oct 01 '20 at 19:24
  • 1
    Yes, it's good practice to export nothing on your "business bundles", to avoid the re-export of api imported – Jonathan Schoreels Oct 01 '20 at 19:24
  • Jsr comes from a required dependency so can't really remove it. Or do you mean to exclude it via exclusions tag ? – cafebabe1991 Oct 01 '20 at 19:25
  • No need to exclude it. It's not intuitive first, but you have to understand that everything your dependencies does, is to generate the packages to import. Once you are in your containers, the packages can come from ANY bundle. So, if you need the jsr dependency jar, but the packages concerned are already exported, you don't need that bundle at all on runtime! Osgi cares about the packages, not from where they come. If Felix exports it, everybody that needs them will have them, even if the maven dependency is not installed. – Jonathan Schoreels Oct 01 '20 at 19:43
  • 1
    I can recommend you the book "osgi in action" that helps a lot – Jonathan Schoreels Oct 01 '20 at 19:43
  • I get that but when you say "uninstall jsr bundle" do mean to go inside karaf and then uninstall it. If so, how do you propose to automate this whole karaf assembly ? – cafebabe1991 Oct 01 '20 at 19:46
  • Wasn't it installed by one of your script? Do your start from a clean karaf? I mean, looking at the bundle numbers it look it was installed for your guava, so I guess you could test with Felix but without installing it before installing guava – Jonathan Schoreels Oct 01 '20 at 19:50
  • No I didn't install it manually. I prepare the whole karaf assembly via a maven project which comprises of a project referring a bunch of other projects getting all those dependencies locked in together via this karaf assembly. Then putting that assembly inside a docker image and testing it. During that test I found this problem. So this whole thing is automated and I couldn't rid myself off that guava. Had I controlled the jar that gave it as a transitive dependency I would have just marked it as optional but I am helpless in that manner – cafebabe1991 Oct 01 '20 at 19:54
  • I see. When you download a "clean karaf", you don't have all those jar already installed (guava isn't there for example). In your case, I think switching to Equinox could unblock your situation, and I think that when you'll be more at ease with how karaf works, you'll be able to remove it. There is multiple place where it could have been added, startup features, deploy folder, system folder, and so on. I worked on a project like this with a custom karaf, you'll figure out with time :) – Jonathan Schoreels Oct 01 '20 at 19:57