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

cha*_*had 15 osgi bundle m2eclipse maven

我在我的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>
Run Code Online (Sandbox Code Playgroud)

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

[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.
Run Code Online (Sandbox Code Playgroud)

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

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

Hil*_*kus 28

这不是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>
Run Code Online (Sandbox Code Playgroud)

接受的答案的问题是,如果类型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>
Run Code Online (Sandbox Code Playgroud)