如何使用deploy:deploy-file将OSGi包部署到Maven仓库?

Cra*_*son 5 osgi bundle nexus maven

我有一个OSGi包,是由另一个团队使用Maven构建的.POM文件将其包装声明为"bundle"并使用Apache Felix插件.

我需要将此工件部署到本地Maven存储库(Nexus),以便我们的内部项目可以使用它.

我已经使用deploy:deploy-file目标将bundle部署到存储库,就像使用标准JAR文件一样,这样可以正常工作.我从包中提取了嵌入的POM并在命令行上传递了它,因此命令行是:

mvn deploy:deploy-file -Dfile=3rdpartybundle.jar -DpomFile=pom.xml -DrepositoryId=internal -Durl=http://internalserver/nexus
Run Code Online (Sandbox Code Playgroud)

问题在于,当我像这样部署它时,打包被设置为bundle,因此存储库中工件的名称最终使用.bundle扩展名,而不是.jar扩展名.

现在,我们无法弄清楚如何将其声明为依赖项.如果我们这样声明:

        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <version>...</version>
            <type>bundle</type>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

我们收到错误,指出无法解决依赖关系.有趣的是,错误消息中的GAV坐标实际上具有"jar"作为依赖类型的值,即使我们将其设置为"bundle".

如果我们将依赖项更改为:

        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <version>...</version>
            <type>jar</type>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

我们得到完全相同的未解决的依赖性错误.

那么你应该如何将打包为捆绑的工件部署到Maven存储库,以便它可以用作另一个项目的编译时依赖?

谢谢

Cra*_*son 1

感谢您的回答,我想我有一个解决方法(但我不会称其为解决方案)。

@earcar 走在正确的轨道上,尽管该解决方案没有利用 pom.xml 中的所有可用信息,而这些信息已经在第 3 方捆绑包中可用(特别是依赖项)。

因此,尽管deploy:deploy-file 的文档有点模糊,但似乎有效的是您可以传递 pom.xml 文件同时设置打包参数。所以我的命令行现在看起来像这样:

mvn deploy:deploy-file -Dfile=3rdpartybundle.jar -DpomFile=pom.xml -DrepositoryId=internal -Durl=http://internalserver/nexus -Dpackaging=jar
Run Code Online (Sandbox Code Playgroud)

通过这种方式,存储库中的 pom.xml 仍然表示打包是“bundle”类型,并包含所有依赖项等,但工件本身具有 .jar 文件扩展名。

然后,当我们将依赖项声明为 JAR 类型时,Maven 能够成功解析它:

    <dependency>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <version>...</version>
        <type>jar</type>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

这基本上解决了我们的问题。但我不确定它的便携性或可靠性如何。FWIW,我们正在运行 Maven 3.0.3

谢谢您的帮助。