如何使用p2-maven-plugin高效管理第三方依赖?
How to efficiently manage third-party dependencies with p2-maven-plugin?
为了管理 Eclipse RCP 应用程序(使用 Tycho 构建)中的第三方依赖项,我使用 p2-maven-plugin 和 Jetty 将 maven 中央工件转换为包,并使它们作为 P2 存储库在我的目标定义文件。我的设置和工作流程如下:
- 在 p2-maven-plugin 的 artifacts 部分添加依赖项。
- 运行目标p2:site重建整个站点。
- 运行码头。
- 重新加载目标。
- 现在我的依赖项在清单文件的依赖项部分可用。
所以我有 3 个问题:
- 每次我想添加新的依赖项时,我都必须重建站点并重新启动 Jetty,有没有办法通过添加 pom 中引用的新依赖项来更新存储库?
- 以下设置是否适用于拥有多个项目的公司:
- 为每个项目创建一个(特定的第三方)远程P2存储库,并相应地配置项目的目标定义。
- 当团队成员需要第三方库时,他可以使用 p2-maven-plugin 生成包,将它们推送到远程存储库并清理 pom 的工件部分。
总而言之,您如何管理团队中的第三方依赖项?
问题是,当您构建 p2 站点时,还会生成 "context.xml" 和 "artifact.xml" 包含捆绑信息的元数据。 p2 解析器使用这些元数据来解析捆绑包。所以我认为如果不重建站点,将很难更新您的 p2 存储库。
我的建议:自从你在团队中工作以来,最明确的方法是为所有第三方依赖项(你可以使用 category.xml).
部署重新创建的 p2 没什么大不了的,您可以在创建站点的同一个 pom 中使用 wagon-maven-plugin
并将其绑定到部署阶段,因此使用 mvn clean deploy
您可以创建存储库并已部署
示例:
<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>
注意:pom 的 distributionManagement 部分中 URL 的 ID 需要与 settings.xml 文件中服务器部分的 ID 相匹配。
在settings.xml中添加服务器:
<server>
<id>my-p2-repository</id>
<username>...</username>
<password>...</password>
</server>
希望这对您有所帮助。
为了管理 Eclipse RCP 应用程序(使用 Tycho 构建)中的第三方依赖项,我使用 p2-maven-plugin 和 Jetty 将 maven 中央工件转换为包,并使它们作为 P2 存储库在我的目标定义文件。我的设置和工作流程如下:
- 在 p2-maven-plugin 的 artifacts 部分添加依赖项。
- 运行目标p2:site重建整个站点。
- 运行码头。
- 重新加载目标。
- 现在我的依赖项在清单文件的依赖项部分可用。
所以我有 3 个问题:
- 每次我想添加新的依赖项时,我都必须重建站点并重新启动 Jetty,有没有办法通过添加 pom 中引用的新依赖项来更新存储库?
- 以下设置是否适用于拥有多个项目的公司:
- 为每个项目创建一个(特定的第三方)远程P2存储库,并相应地配置项目的目标定义。
- 当团队成员需要第三方库时,他可以使用 p2-maven-plugin 生成包,将它们推送到远程存储库并清理 pom 的工件部分。
总而言之,您如何管理团队中的第三方依赖项?
问题是,当您构建 p2 站点时,还会生成 "context.xml" 和 "artifact.xml" 包含捆绑信息的元数据。 p2 解析器使用这些元数据来解析捆绑包。所以我认为如果不重建站点,将很难更新您的 p2 存储库。
我的建议:自从你在团队中工作以来,最明确的方法是为所有第三方依赖项(你可以使用 category.xml).
部署重新创建的 p2 没什么大不了的,您可以在创建站点的同一个 pom 中使用
wagon-maven-plugin
并将其绑定到部署阶段,因此使用mvn clean deploy
您可以创建存储库并已部署
示例:
<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>
注意:pom 的 distributionManagement 部分中 URL 的 ID 需要与 settings.xml 文件中服务器部分的 ID 相匹配。
在settings.xml中添加服务器:
<server>
<id>my-p2-repository</id>
<username>...</username>
<password>...</password>
</server>
希望这对您有所帮助。