通过解析来自 Maven 存储库的 Tycho 功能来构建 p2 存储库 [英] Building a p2 repository by resolving Tycho features from a Maven repository

查看:34
本文介绍了通过解析来自 Maven 存储库的 Tycho 功能来构建 p2 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从部署在远程 Maven 存储库中的 Tycho 功能构件构建 p2 存储库,而不必先将构件安装到本地 Maven 存储库中(如 Tycho 无法解析从产品到来自不同反应堆构建的 eclipse-feature 的引用),并且没有必须在单个反应器构建中一起构建所有功能和存储库.

I'm trying to build a p2 repository from Tycho feature artifacts which are deployed in a remote Maven repository, without having to install the artifacts into the local Maven repository first (as in Tycho fails to resolve reference from product to eclipse-feature from a different reactor build), and without having to build all features and the repository together in a single reactor build.

背景

我有一个构建多个 Eclipse 插件和功能的多模块 Tycho 项目.

I have a multi-module Tycho project that builds several Eclipse plugins and features.

以便我可以单独构建每个模块 - 以便我可以在我们的 Nexus Maven 存储库中引用 OSGI 工件 - 我已在我的目标平台中启用 <pomDependencies>consider</pomDependencies>,并像往常一样使用 <dependency/> 元素在模块之间或存储库工件中添加 Maven 依赖项.

So that I can build each module separately - and so that I can reference OSGI artifacts in our Nexus Maven repository - I have enabled <pomDependencies>consider</pomDependencies> in my target platform, and added Maven dependencies between the modules or to the repository artifacts as usual with <dependency/> elements.

这很好用 - 我可以构建功能或运行插件测试,而无需它们的依赖插件位于我的本地 Maven 存储库或相同的反应器构建中.例如,当我在插件测试项目上运行 mvn test 时,相关的依赖项将从 Nexus 下载,Tycho 将愉快地解决我清单中的 Import-Package这些,构建一切并运行测试.到目前为止一切顺利.

This works well - I can build the features or run the plugin tests without their dependant plugins being either in my local Maven repository or in the same reactor build. For example, when I run mvn test on a plugin test project, the relevant dependencies will be downloaded from Nexus and Tycho will happily resolve the Import-Packages in my manifest against these, build everything and run the tests. So far so good.

我想从这些功能中生成一个 p2 存储库,以便我可以从更新站点将它们安装到 Eclipse 中,并且宣传的方法是使用 eclipse-repository 包装类型.但是这里的计划失败了——Tycho 似乎无法在构建存储库时解决功能依赖关系,就像它在构建功能时解决插件依赖关系一样.所有尝试都成功:

I would like to generate a p2 repository from these features so that I can install them in Eclipse from an update site, and the advertised way to do this is with the eclipse-repository packaging type. But here the plan falls down - Tycho doesn't seem to be able to resolve feature dependencies when building repositories in the same way as it can resolve plugin dependencies when building features. All attempts yield:

[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: my.eclipse.repository raw:0.0.1.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.0.1-SNAPSHOT
[ERROR]   Missing requirement: my.eclipse.repository raw:0.0.1.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.0.1-SNAPSHOT requires 'my.prj.eclipse.project.feature.feature.group 0.0.0' but it could not be found

我有两种方法成功构建了 p2 存储库:

There are two ways I have successfully built the p2 repository:

  • 作为同一反应堆构建的一部分.如果我将 eclipse-repository 作为 Tycho 多模块项目中的一个模块,并使用例如mvn verify,功能解析正常.但我不想这样做.我更愿意单独构建模块.这意味着我们的 CI 可以对每个模块都有一个指标,我们可以立即看到哪些模块测试失败了;它为我们提供了并行构建的机会;我们避免了在没有改变的模块上不断运行构建.不得不使用单体 Maven 构建将是一种耻辱.
  • 如果我将 Tycho 项目安装到我的本地 Maven 存储库中,请在依赖项上运行 mvn install.但我也不想这样做,因为这意味着构建本质上是不可重现的,因为它对本地存储库的状态很敏感.我们的 CI 目前设置为为每个作业维护一个 Maven 存储库,并在执行开始时将其完全擦除,以保护我们免受这种潜在的混乱.
  • As part of the same reactor build. If I make the eclipse-repository a module within the Tycho multi-module project, and build the whole project at once with e.g. mvn verify, the features are resolved fine. But I don't want to do this. I would prefer to build modules individually. This means our CI can have an indicator for each module, and we can immediately see what module tests have failed in; it gives us opportunities for parallelising builds; and we avoid having to be constantly running builds on modules that haven't changed. It would be a shame to have to use a monolithic Maven build.
  • If I install the Tycho project into my local Maven repository, by running mvn install on the dependency. But I don't want to do this either, because this would mean the build is inherently irreproducable, as it would be sensitive to the state of the local repository. Our CI is currently set up to maintain a Maven repository per job and to completely wipe it at the start of execution, to shield us from this potential messiness.

所以我的问题是:有第三种方法吗?有什么方法可以让 Tycho 插件负责构建 eclipse-repository 包装类型以从远程 Maven 存储库下载功能?或者我可以通过任何其他方式从单独构建并部署到 Maven 存储库的插件构建 p2 存储库?

So my question is: is there a third way? Is there any way I can get the Tycho plugin responsible for building eclipse-repository packaging types to download features from a remote Maven repository? Or any other way I can build the p2 repository from plugins that have been individually built and deployed to the Maven repository?

我尝试过的事情包括:

  • 将 Maven 功能依赖项指定为 jareclipse-feature
  • 向目标平台显式添加功能,例如

  • specifiying the Maven feature depedencies as both jar and eclipse-feature
  • explicitly adding the features to the target platform, like

<代码>...<artifactId>目标平台配置</artifactId><version>${tycho.version}</version><配置><依赖解析><额外要求><要求><type>eclipse-feature</type><id>my.prj.eclipse.project.feature</id><versionRange>0.0.0</versionRange></要求>...

我发现最接近的解决方案是拥有一个仅包含存储库和功能的多模块 Tycho 项目.

The closest thing I've found to a decent solution is have a multi-module Tycho project that just contains the repository and features.

feature-project
 |- feature1    (eclipse-feature)
 |- feature2    (eclipse-feature)
 |- repository  (eclipse-repository)

构建此作品 - 添加到顶级 POM 的所有插件都从 Nexus 下载,可用于包含在每个功能中并包含在生成的存储库中.

Building this works - all plugins added to the top-level POM are downloaded from Nexus, available for inclusion in each feature and included in the generated repository.

但这远非理想,因为我无法再将我的功能逻辑地存储在我的插件旁边;它们需要位于不同的项目层次结构中.尝试单独构建功能和存储库,例如使用 mvn clean verify -pl :feature1,feature2,repository,可能由于 错误 380152.

However this is far from ideal because I can no longer store my features logically alongside my plugins; they need to be in separate project hierarchies. Attempting to build the features and repository separately, like with mvn clean verify -pl :feature1,feature2,repository, fails presumably due to Bug 380152.

有没有更好的方法?任何帮助将不胜感激.

Is there a better way? Any help would be gratefully received.

非常感谢

(顺便说一句:使用 mvn clean verify -Dtycho.localArtifacts=ignore 构建存储库如果功能存在于本地 Maven 存储库中,将成功'不向您显示正在从本地 repo 解决工件的警告...这是一个错误吗?)

(As an aside: building the repository with mvn clean verify -Dtycho.localArtifacts=ignore will succeed if the features are present in the local Maven repository, and won't show you the warning that artifacts are being resolved from the local repo... is this a bug?)

推荐答案

您的透彻分析给我留下了深刻的印象.您几乎已经掌握了当前 Tycho 版本 (0.22.0) 可能涵盖的所有内容 - 除了非常不直观的解决方案,我没想到任何人都能猜到它(见下文).但请注意,还需要进行小修复才能使解决方案适用于 SNAPSHOT 工件.

I am pretty impressed by your thorough analysis. You've almost got everything covered which is possible with the current Tycho version (0.22.0) - except for the solution which is so unintuitive that I wouldn't have expected anyone to be able to guess it (see below). Note however that there is a small fix required to also make the solution work for SNAPSHOT artifacts.

但首先,我想为您所观察到的内容提供一些技术(和历史)背景:

But first, I'd like to provide some technical (and historical) background for what you have observed:

pomDependencies=consider 仅适用于插件:此功能的用例是允许从 Maven 存储库引用插件(或更准确地说是 OSGi 包).因此,当设置了标志并且项目对 JAR 有依赖关系时,Tycho 将检查它们是否是 OSGi 包,即时为它们生成 p2 元数据,并将它们添加到目标平台.功能 JAR 没有类似的支持,因为这些 JAR 通常不存在于 Maven 存储库中.

pomDependencies=consider only works for plug-ins: The use case for this functionality was to allow referencing plug-ins (or more precisely OSGi bundles) from Maven repositories. So when the flag is set and the project has dependencies to JARs, Tycho will check if they are OSGi bundles, generate the p2 metadata for them on-the-fly, and add them to the target platform. There is no similar support for feature JARs because these usually don't exist in Maven repositories.

但是第谷建造的项目呢?这些可能会部署到 Maven 存储库中! 是的,这是真的,这就是为什么我尝试扩展 pomDependencies 概念以允许您尝试执行的操作.这个想法是,每次 Tycho 考虑目标平台的 POM 依赖项时,它还会检查 p2 索引文件 ...-p2metadata.xml...-p2artifacts.xml 存在.然而,事实证明这会导致巨大的性能损失,因为 Maven 存储库服务器通常需要很长时间才能确定工件不存在.因此远程下载被禁用,取而代之的是在 local Maven 存储库中的查找.这样,两个 Tycho 构建可以设置 -Dtycho.localArtifacts=ignore 并且仍然能够通过本地 Maven 存储库交换 POM 中指定的工件.

But what about Tycho-built projects? These may deploy into Maven repositories! Yes, this is true, and this is why I tried to extend the pomDependencies concept to allow for what you are trying to do. The idea was that every time Tycho considers a POM dependency for the target platform, it also checks if the p2 index files ...-p2metadata.xml and ...-p2artifacts.xml exist. However this turned out to infer a massive performance penalty because it generally takes very long for a Maven repository server to figure out that an artifact does not exist. So the remote download was disabled, and replaced with a look-up in the local Maven repository. In this way, two Tycho builds could set -Dtycho.localArtifacts=ignore and would still be able to exchange the artifacts specified in the POM via the local Maven repository.

了解了这些实现细节,我们得到了以下解决方案:您不仅需要将存储库中的 POM 依赖项添加到功能工件,还需要将依赖项添加到 p2metadata 和 p2artifacts 文件中.示例:

Knowing these implementation details, we get to the following solution: Instead of only adding a POM dependency from the repository to the feature artifact, you also need to add dependencies to the p2metadata and p2artifacts files. Example:

<dependencies>
    <dependency>
        <groupId>myproject</groupId>
        <artifactId>myproject.feature</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>myproject</groupId>
        <artifactId>myproject.feature</artifactId>
        <version>0.1.0-SNAPSHOT</version>
        <classifier>p2metadata</classifier>
        <type>xml</type>
    </dependency>
    <dependency>
        <groupId>myproject</groupId>
        <artifactId>myproject.feature</artifactId>
        <version>0.1.0-SNAPSHOT</version>
        <classifier>p2artifacts</classifier>
        <type>xml</type>
    </dependency>
</dependencies>

这使得 Maven 也下载了这些 p2 索引文件,因此 Tycho 将主要工件识别为 Tycho 工件.通过这种方式,您还可以通过 POM 依赖项将 eclipse-feature 导入目标平台 - 至少几乎是:使用 0.22.0,存储库构建通过,但缺少 feature.jar 工件.这个问题我已经调试过了,很容易修复.

This makes Maven also download these p2 index files, so Tycho recognizes the main artifact as Tycho artifact. In this way, you can also get an eclipse-feature into the target platform via POM dependencies - at least almost: With 0.22.0, the repository build passes, but the feature.jar artifact is missing. I already debugged this issue, and it is easy to fix.

显然,每个实际依赖项的三个 <dependency> 元素的语法并不好.应该可以将其归结为单个 p2artifacts 元素 - 但这是更多工作.如果您对此功能感兴趣,可以在 Tycho 的问题跟踪器中打开增强请求.

Obviously the syntax with three <dependency> elements for every actual dependency is not nice. It should be possible to boil this down to a single p2artifacts element - but this is more work. In case you are interested in this feature, you could open an enhancement request in Tycho's issue tracker.

这篇关于通过解析来自 Maven 存储库的 Tycho 功能来构建 p2 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆