简体   繁体   English

如何使用p2-maven-plugin有效管理第三方依赖?

[英]How to efficiently manage third-party dependencies with p2-maven-plugin?

In order to manage third-party dependencies in an Eclipse RCP application (built with Tycho) I am using the p2-maven-plugin and Jetty to convert maven central artifacts to bundles and make them available as a P2 repository in my Target definition file. 为了管理Eclipse RCP应用程序(使用Tycho构建)中的第三方依赖项,我使用p2-maven-plugin和Jetty将maven中心工件转换为bundle,并将它们作为我的Target定义文件中的P2存储库提供。 My setup and workflow is as follows : 我的设置和工作流程如下:

  • Add the dependency in the artifacts section of the p2-maven-plugin. 在p2-maven-plugin的工件部分中添加依赖项。
  • run the goal p2:site which rebuild the entire site. 运行目标p2:重建整个站点的站点。
  • run jetty. 跑码头。
  • Reload the Target. 重新加载目标。
  • And now my dependency is available in the dependency section of the Manifest file. 现在我的依赖项可以在Manifest文件的依赖项部分中找到。

So I have 3 questions: 所以我有3个问题:

  • Each time I want to add a new dependency I have to rebuild the site and restart Jetty, is there a way to just update the repository by adding new dependencies referred in the pom ? 每次我想添加一个新的依赖项我必须重建站点并重新启动Jetty,有没有办法通过添加pom中引用的新依赖项来更新存储库?
  • Would the following setup be suitable in the context of company with multiple projects : 以下设置是否适用于具有多个项目的公司:
    • Create a (specific third-party) remote P2 repository for each project and configure the target definition of the project accordingly. 为每个项目创建(特定的第三方)远程P2存储库,并相应地配置项目的目标定义。
    • When a team member wants a third-party library, he can use p2-maven-plugin to generate bundles, push them in the remote repository and clean the artifact section of the pom. 当团队成员想要第三方库时,他可以使用p2-maven-plugin生成包,将它们推送到远程存储库并清理pom的工件部分。

To conclude, how do you manage third-party dependencies in your team ? 总而言之,您如何管理团队中的第三方依赖项?

  • the problem is, when you build a p2 site metadata will be generated also "context.xml" and "artifact.xml" containing the bundels inforamtion. 问题是,当你构建一个p2站点元数据时,还会生成包含bundels信息的“context.xml”和“artifact.xml”。 these metadata used by the p2 resolver for resolvin the bundles. p2解析器用于解析捆绑包的这些元数据。 so i think without rebuilding the site it will be a hard way to get your p2 repo updated. 所以我认为如果不重建网站,将很难让你的p2 repo更新。

    my suggestion: the clearst way to go since you working in a team is to have a standalone Repository (nexus, jetty, tomcat...) for all third party dependencies ( you may use the category.xml ). 我的建议:自从你在团队中工作以来,最简单的方法是为所有第三方依赖项建立一个独立的存储库(nexus,jetty,tomcat ......)(你可以使用category.xml )。

    deploying the recreated p2 is not a big deal you can use wagon-maven-plugin in the same pom creating your site and bind it to the deploy phase, so with mvn clean deploy you get your repository created and deployed 部署重新创建的p2并不是什么大问题,您可以在同一个pom中使用wagon-maven-plugin创建您的站点并将其绑定到部署阶段,因此使用mvn clean deploy可以创建和部署您的存储库

Example: 例:

<build>
<plugins>
    <plugin>
        <groupId>org.reficio</groupId>
        <artifactId>p2-maven-plugin</artifactId>
        <version>1.2.0-SNAPSHOT</version>
        <executions>
            <execution>
                <id>default-cli</id>
                <configuration>
                    <artifacts>
                        <!-- specify your depencies here -->
                        <!-- groupId:artifactId:version -->
                        <artifact><id>commons-io:commons-io:2.1</id></artifact>
                        <artifact><id>commons-lang:commons-lang:2.4</id></artifact>
                        <artifact><id>commons-lang:commons-lang:2.5</id></artifact>
                        <artifact><id>commons-lang:commons-lang:2.6</id></artifact>
                        <artifact><id>org.apache.commons:commons-lang3:3.1</id></artifact>
                    </artifacts>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>wagon-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <id>upload-repo</id>
                <phase>deploy</phase>
                <goals>
                    <goal>upload</goal>
                </goals>
                <configuration>
                    <fromDir>${project.build.directory}/repository/</fromDir>
                    <includes>*/**</includes>
                    <serverId>my-p2-repository</serverId>
                    <url>dav:http://mycompany.com/../content/repositories</url>
                    <toDir>thirdparty-p2-repository</toDir>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
<extensions>
    <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-webdav-jackrabbit</artifactId>
        <version>1.0-beta-7</version>
    </extension>
</extensions>

<distributionManagement>
        <repository>
            <id>my-p2-repository</id>
            <url>dav:http://mycompany.com/../content/repositories</url>
        </repository>
</distributionManagement>

Note: The ID of the URL in the distributionManagement section of your pom needs to match the ID of a server section in your settings.xml file. 注意:pom的distributionManagement部分中URL的ID需要与settings.xml文件中服务器部分的ID匹配。

add the server in settings.xml: 在settings.xml中添加服务器:

<server>
 <id>my-p2-repository</id>
 <username>...</username>
 <password>...</password>
</server>

hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM