为什么maven找不到osgi bundle依赖?

时间:2012-03-29 20:22:27

标签: maven osgi bundle m2eclipse

我已经在我的maven项目中声明了一个OSGi包作为依赖项。 (它恰好是felix容器。)

<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.framework</artifactId>
    <version>4.0.2</version>
    <type>bundle</type>
    <scope>compile</scope>
</dependency>

当我尝试构建时,它说它无法找到它。

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) org.apache.felix:org.apache.felix.framework:bundle:4.0.2

  Try downloading the file manually from the project website.

但是,快速查看中心会验证这个神器确实存在。我注意到,如果我将其更改为“jar”类型,它确实会为我下载jar( bundle )。这让我思考,为什么我首先称它为捆绑?好吧,我这样做是因为当我使用m2e查找工件时,它称之为“捆绑”;实际上,m2e生成了我在上面引用的那些坐标。

bundle不是有效的maven工件类型吗?如果没有,为什么m2e称之为?

1 个答案:

答案 0 :(得分:27)

这不是m2e中的故障,如公认的答案所述。问题是maven不知道“捆绑”类型是什么。所以你需要添加一个定义它的插件,即maven-bundle-plugin。请注意,您还需要将 extensions 属性设置为true。所以POM应该有类似

的东西
<plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <version>2.4.0</version>
      <extensions>true</extensions>
</plugin>

接受答案的问题是,如果类型bundle的依赖关系是直接依赖,它就有效;因为它是你的pom声明它,你可以删除类型。但是,如果您的依赖项本身具有类型 bundle 的依赖关系,那么您就会被搞砸,因为您的一个传递依赖项是bundle类型,并且您不能只删除其中的类型,因为您不是该工件并且无法访问pom,这也是您当前的执行无法理解的。它会尝试寻找repo/your-dependency.bundle

使用依赖插件复制依赖项时遇到了这个问题。在这种情况下,插件依赖必须进入插件本身。您只需要依赖插件就可以了解bundle插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.4.0</version>
            <type>maven-plugin</type>

        </dependency>
    </dependencies>
    <extensions>true</extensions>
</plugin>