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

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

问题描述

我正在尝试从部署在远程Maven存储库中的Tycho功能工件构建p2存储库,而不必先将工件安装到本地Maven存储库中(如

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.

背景

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

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

以便可以分别构建每个模块-以便可以在Nexus Maven存储库中引用OSGI工件-我已在目标平台中启用了<pomDependencies>consider</pomDependencies>,并在模块之间或将存储库工件添加为Maven依赖项,如下所示:通常使用<dependency/>元素.

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构建是可耻的.
  • 如果我通过在依赖项上运行mvn install将Tycho项目安装到本地Maven存储库中.但是我也不想这样做,因为这将意味着该构建本质上是不可复制的,因为它将对本地存储库的状态敏感.目前,我们已设置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>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <dependency-resolution> <extraRequirements> <requirement> <type>eclipse-feature</type> <id>my.prj.eclipse.project.feature</id> <versionRange>0.0.0</versionRange> </requirement> ...

... <artifactId>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <dependency-resolution> <extraRequirements> <requirement> <type>eclipse-feature</type> <id>my.prj.eclipse.project.feature</id> <versionRange>0.0.0</versionRange> </requirement> ...

我发现一个体面解决方案的最接近的事情是有一个仅包含存储库和功能的多模块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.

非常感谢

(顺便说一句:如果本地Maven存储库中存在功能,则使用mvn clean verify -Dtycho.localArtifacts=ignore构建存储库将成功,并且不会向您显示警告,指出已从当地仓库...这是一个错误吗?)

(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的类似支持,因为它们通常在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.

但是,第谷(Tycho)建造的项目呢?这些可能会部署到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功能引入目标平台-至少几乎是这样:在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天全站免登陆