由于多个 Joda-Time 版本,Karaf 无法根据 ActiveMQ 功能解析包

Karaf is unable to resolve bundle depending on ActiveMQ feature due to multiple Joda-Time versions

我的包具有对 Joda-Time 2.x 的转换包依赖性,并通过 Karaf (3.0.3) 功能文件进行部署。它部署得很好,直到我将依赖项添加到 Karaf 提供的 activemq-broker (5.11.1) 和 activemq-camel 功能。我的包现在无法解析,因为找到了包 "org.joda.time" 的两条路径。一个是我依赖的 2.7 版本,另一个是 1.6 版本,它是 ActiveMQ 特性的传递依赖:

Chain 1:
  ch.vivates.ams.pep [152.9]
    import: (&(osgi.wiring.package=org.joda.time)(version>=2.7.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package=org.joda.time
  joda-time [64.0]

Chain 2:
  ch.vivates.ams.pep [152.9]
    import: (osgi.wiring.package=org.apache.activemq)
     |
    export: osgi.wiring.package=org.apache.activemq; uses:=com.thoughtworks.xstream
  org.apache.activemq.activemq-osgi [108.0]
    import: (&(osgi.wiring.package=com.thoughtworks.xstream)(version>=1.4.0)(!(version>=2.0.0)))
     |
    export: osgi.wiring.package=com.thoughtworks.xstream; uses:=org.joda.time
  org.apache.servicemix.bundles.xstream [118.0]
    import: (&(osgi.wiring.package=org.joda.time)(version>=1.6.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package=org.joda.time
  joda-time [117.0]

我可以通过在安装功能之前显式启动 Joda-Time 2.7 包来成功安装我的功能:

bundle:install -s mvn:joda-time/joda-time/2.7

重新启动 Karaf 后,由于同样的原因,我的包无法启动,我首先必须刷新 Joda-Time 2.7 包。只有在那之后我的包才会开始。

解决这些问题的 "proper" 方法是什么?尤其是重新启动 Karaf 时的那个?我想我可以通过在我自己的包中嵌入 Joda Time v2.7 来解决这个问题,但这只是一个技巧。

目前该功能如下所示:

<feature name="name" version="3.0.0-SNAPSHOT" description="description">
        <details>details</details>
        <feature>http</feature>
        <feature>http-whiteboard</feature>
        <feature version="5.11.1">activemq-broker-noweb</feature>
        <feature version="2.14.1">camel-core</feature>
        <feature version="2.14.1">camel-blueprint</feature>
        <feature version="2.14.1">camel-netty4-http</feature>
        <feature version="2.14.1">camel-http4</feature>
        <feature version="2.14.1">camel-jms</feature>
        <feature version="5.11.1">activemq-camel</feature>
        <bundle dependency="true">mvn:my.package/base/3.0.0-SNAPSHOT</bundle>
        <bundle>mvn:my.package/myBundle/3.0.0-SNAPSHOT</bundle>
        <bundle>mvn:joda-time/joda-time/2.7</bundle>
        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.opensaml/2.6.1_3</bundle>
        <bundle>mvn:commons-lang/commons-lang/2.6</bundle>
        <bundle>wrap:mvn:org.owasp.esapi/esapi/2.0.1</bundle>
        <bundle>mvn:org.apache.santuario/xmlsec/1.5.6</bundle>
        <bundle>mvn:org.bouncycastle/bcprov-jdk15/1.46</bundle>
        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/3.1_7</bundle>
        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-collections/3.2.1_3</bundle>
        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.not-yet-commons-ssl/0.3.11_1</bundle>
        <bundle>mvn:org.codehaus.woodstox/woodstox-core-asl/4.4.1</bundle>
        <bundle>mvn:org.codehaus.woodstox/stax2-api/3.1.4</bundle>
        <bundle>mvn:org.herasaf.xacml.core/herasaf-xacml-core/1.0.0.RELEASE</bundle>
        <bundle>mvn:net.sf.ehcache/ehcache/2.9.0</bundle>
        <bundle>mvn:commons-codec/commons-codec/1.9</bundle>
        <bundle>mvn:commons-io/commons-io/2.4</bundle>
</feature>

编辑:

这个issue describes the same problem for the Camel Salesforce component. Apparently this was fixed by widening the version range的导入到[1.6,3)。 ActiveMQ 包应用相同的版本范围,但它仍然会产生问题。

上述场景是 Neil Bartlett blog post 中描述的问题的变体。由于我无法控制 ActiveMQ 的直接和传递依赖性,所以我能看到的唯一选项是

  1. 降级我自己的 Joda-Time 依赖项以匹配 xstream
  2. 使用的版本
  3. Statically link/在我自己的包中嵌入 Joda-Time 2.7

我选择了选项 2)。