Tycho和Eclipse:如何在Eclipse中开发时解决OSGI依赖关系到我自己的捆绑包,而不会在IDE中打开它们 [英] Tycho and Eclipse: How to resolve OSGI dependencies to my own bundles at development time within Eclipse, without opening all of them in the IDE

查看:329
本文介绍了Tycho和Eclipse:如何在Eclipse中开发时解决OSGI依赖关系到我自己的捆绑包,而不会在IDE中打开它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



我的Eclipse RCP应用程序是使用Tycho构建的。它由多个组件(以OSGi软件包/ Eclipse插件的形式)组成。其中一个组件包含产品文件并实现产品的实现。



应用程序根目录下有一个反应堆POM,它按顺序构建所有组件,但我也想构建其他组件(使用 mvn deploy )。



构建如此单个组件的工作原理如下:


  1. 从公司(p2)存储库检索所有组件的依赖关系的最新版本。

  2. 构建组件。

  3. 将组件部署到我们的公司存储库,以作为其他组件本身的依赖。



注意:我们的存储库是在Nexus上托管的普通的maven2 存储库,其RCP工件也自动映射到p2存储库格式。这样,Tycho可以使用p2存储库格式来查找依赖关系,而可以使用标准的Maven部署。这样做很好。



注意:我的父POM确保我们在p2存储库URL中查找依赖关系。部署URL是存储库的默认maven2格式位置。



问题



通过命令行构建单个组件( mvn deploy ),Maven查找p2存储库中的项目内依赖关系,并正确解析(即最新版本自动下载并在构建中使用)。



但是,当在Eclipse中开发时,IDE无法解决它们。清单文件在我的项目内依赖关系中给出错误,无法解决。



问题



我的问题是:如何使Eclipse IDE在以下任一方面查找依赖项(和新版本的依赖项):




  • 我的本地p2存储库(〜/ .m2 / repository / p2 / osgi / bundles

  • 我的公司p2仓库( nexus.mycompany.com/myproduct-snapshots/.meta/p2



理想情况下,对于他们,每次都可以获取最新版本,如果有更新版本可用。



如果不使用POM中的p2存储库URL,我应该如何配置Eclipse?



示例



考虑一个eclipse插件 com.mycompany.myproduct.fancy ,这取决于另一个eclipse插件 com.mycompany.myproduct.core 。两者都有一个POM(配置为Tycho使用),(通过他们的父POM)使我的Nexus资源库配置正确:maven2存储库URL部署和p2存储库URL寻找依赖关系。



首先我将核心插件部署到我的maven仓库(使用默认的 mvn deploy )。 Nexus存储库将以maven和p2格式提供此部署的插件。



当我构建花式组件通过命令行(使用 mvn install ),(早期部署的)核心组件被自动找到并下载。

  project / com.mycompany.myproduct.fancy $ mvn clean install 
<在p2仓库中搜索,下载核心> ;
<构建花式>
< SUCCESS>

当我打开一个新的Eclipse工作区并打开花式 component,它的Manifest(包含它的依赖项)会出现以下错误:

  Bundle'com.mycompany.myproduct。核心无法解决。 

我的问题是:如何开发花式组件,而不需要在Eclipse中打开 core 作为项目。



投机



这是我身边的一些猜测。请纠正我,如果我错了,任何其他解决方案的实际问题也欢迎!




  • 我知道> Eclipse IDE的插件目前将Maven POM映射到Eclipse概念(使用m2e连接器)。我已经安装了专用的Tycho连接器。例如,mvn编译步骤实际上是由Eclipse JDT编译器执行的。


  • 我也知道,当一个完整的Tycho产品在Eclipse中启动时,在Eclipse PDE环境中运行。例如,我需要在我的运行配置中指定目标平台。


  • 我知道我可以打开我的Eclipse工作区中的所有组件。这将解决问题,但是不可行,因为我有很多组件,这将破坏独立的组件开发。


  • 我假设Eclipse m2e映射和/或PDE构建环境不够聪明,无法在构建时自动获取(最新)依赖项。如果我错了请纠正我:)


  • 因此,我认为我需要在构建时指定目标平台。我已经看过窗口>首选项>插件开发>目标平台。我可以将我们的p2存储库添加到目标平台,解决问题。但是这样做有很多问题:




    • 我需要一个包含所有组件功能的功能。只有功能可以添加。

    • 每次我部署一个单一组件的新版本,我将不得不重建完整的功能(在我们的p2存储库中创建一个新的功能版本)。

    • 每次更新组件并构建功能时,我都必须手动更改目标平台。


  • 如果上述都是正确的,我推测我需要一个m2e连接器(或与当前不同的连接器)实际检查POM中指定的p2存储库,当解析OSGi依赖关系并自动添加



解决方案

如Nick Wilson所示将需要安装 m2e Tycho Configurator ,它基本上链接Eclipse和Tycho(即,使Tycho可在Eclipse中使用)。



安装m2e后,您应该已经指向了,但您也可以手动安装:


  1. 转到窗口>首选项> Maven>发现。


  2. 点击打开目录按钮。这将打开m2e Marketplace窗口。


  3. 搜索tycho,这应该是Tycho Configurator作为唯一的搜索结果。 p>


  4. 点击完成,完成了。


我也遇到过这个问题,找到解决方案并不简单,所以我希望这有帮助!


Background

My Eclipse RCP application is built using Tycho. It consists of multiple components (in the form of OSGi bundles/Eclipse plug-ins). One of these component contains the product file and materializes the product.

There is a reactor POM at the application root, which builds all components in order, but I also want to build other components independently (using mvn deploy) .

Building such a single component works as follows:

  1. Retrieve the latest versions of all the component's dependencies from our company (p2) repository.
  2. Build the component.
  3. Deploy the component to our company repository to be used as a dependency for other components itself.

Note: Our repository is a normal maven2 repository hosted on a Nexus, whose RCP artifacts are automatically mapped to a p2 repository format as well. This way, Tycho can use the p2 repository format to find dependencies, while the standard Maven deployment can be used. This works fine.

Note: My parent POM makes sure that we look for dependencies at the p2 repository URL. The deployment URL is the default maven2 format location of the repository. This works fine.

Problem

When building such a single component through the command-line (mvn deploy), Maven looks for intra-project dependencies in the p2 repository and they are correctly resolved (i.e. latest version is automatically downloaded and used in build).

However, when developing in Eclipse, the IDE cannot resolve them. The manifest files gives an error at each of my intra-project dependencies that they cannot be resolved.

Question

My question is: How can I make the Eclipse IDE look for dependencies (and new versions of dependencies) in either:

  • My local p2 repository (~/.m2/repository/p2/osgi/bundles)
  • My company p2 repository (nexus.mycompany.com/myproduct-snapshots/.meta/p2)

Ideally, it would look for them every time and fetch the latest version if a newer version is available.

If it does not use the p2 repository URLs in the POM, how should I configure Eclipse?

Example

Consider an eclipse plug-in com.mycompany.myproduct.fancy, which depends on another eclipse plug-in com.mycompany.myproduct.core.

Both also have a POM (configured for Tycho use), which (through their parent POM) have my Nexus repositories configured correctly: maven2 repository URL for deployment and p2 repository URL to look for dependencies.

First I deploy the core plug-in to my maven repository (using the default mvn deploy). The Nexus repository will provide this deployed plug-in in both maven and p2 format.

When I build the fancy component through the command line (using mvn install), the (earlier deployed) core component is found and downloaded automatically.

project/com.mycompany.myproduct.fancy$ mvn clean install
<searches in p2 repository, download core>
<builds fancy>
<SUCCESS>

When I open a new Eclipse workspace and open the fancy component, its Manifest (which contains its dependencies) gives the following error:

Bundle 'com.mycompany.myproduct.core' cannot be resolved.

My question is: how can I develop the fancy component in the Eclipse IDE without the need to open core as project in Eclipse.

Speculation

This is some speculation from my side. Please correct me if I'm wrong and any other solution to the actual problem is also welcome!

  • I know the m2e plug-in of the Eclipse IDE currently maps Maven POMs to Eclipse concepts (using m2e connectors). I have installed the dedicated Tycho connectors. For example, the mvn compile step is actually performed by the Eclipse JDT compiler.

  • I also know that when a complete Tycho product is started in Eclipse, it is run in the Eclipse PDE environment. For example, I need to a specify a target platform in my Run configuration.

  • I know I can open all components in my Eclipse workspace. This would solve the problem, but is not feasible as I have many components and this would break independent component development.

  • I assume the Eclipse m2e mapping and/or the PDE build environment is not smart enough to fetch (latest) dependencies automatically at build time. Please correct me if I'm wrong. :)

  • Therefore, I assume I need to specify the target platform at build time too. I have taken a look at Window > Preferences > Plug-in Development > Target Platform. I can add our p2 repository to the Target Platform, which solves the problem. However this gives many problems:

    • I need a feature containing all components for this to work. Only features can be added.
    • Every time I deploy a new build of a single component, I would have to rebuild the complete feature (to create a new feature version on our p2 repository).
    • Every time I update a component and build the feature, I would have to manually change the Target Platform.
  • If the above is all correct, I speculate I need an m2e connector (or a different one from the current one) that actually checks the p2 repositories specified in the POM when resolving the OSGi dependencies and automatically adds those to the target platform.

解决方案

As indicated by Nick Wilson, you will need to install the m2e Tycho Configurator, which basically "links up" Eclipse and Tycho (i.e., makes Tycho available in Eclipse).

You should've been pointed towards it after having installed m2e, but you can also install it manually:

  1. Go to Window > Preferences > Maven > Discovery.

  2. Click the "Open Catalog" button. This will open the "m2e Marketplace" window.

  3. Search for "tycho", this should give you the "Tycho Configurator" as sole search result.

  4. Click "Finish", you're done.

I've had this issue as well, and it isn't simple to find the solution, so I hope this helps!

这篇关于Tycho和Eclipse:如何在Eclipse中开发时解决OSGI依赖关系到我自己的捆绑包,而不会在IDE中打开它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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