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
Asked Answered
O

2

10

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.

Occasion answered 12/9, 2013 at 8:22 Comment(4)
Have you got both the m2e plugins and the Tycho Configurator installed?Cadmarr
Yes, m2e is installed. My bundles are configured as both Maven projects and plug-ins (i.e. the builders of the project are Java Builder, Plug-in Manifest Builder, Extension Point Schema Builder and Maven Project Builder). The Maven Lifecycle Mapping was configured automatically for Tycho. I don't know what you mean with 'Tycho Configurator'?Occasion
Sounds very similar to what I am trying to do, but I'm having all sorts of trouble. Would you be able to share your poms? Did you get this working on Nexus OSS?Washroom
tbacker, have you figured this out. I'm in the exact same boat as you right now with having a company p2 setup and developing components that use it. Maven on the command line works perfectly but m2e + tycho configurator installed is not able to resolve my dependencies. One thing I noticed is if I right click on a plugin and select "Properties..." and go to Maven/Lifecycle Mapping, the only executions are "resources:resources" then "resources:testResources" all the tycho ones are set to "ignore"Creigh
D
5

The "most automated" way to configure your target platform in Eclipse is to use a target file. That file can be checked in with your sources, so every developer only needs to open the file and click on "Set as Target Platform" to activate it. AFAIK there is no m2e connector or Eclipse plug-in which does that automatically.

Given your development process, setting up this target file is a little more tricky. Since you don't have a feature which contains the latest version of all your bundles, you need to include the bundles directly in the target file. This is not possible via the rich editor, but can be done with a text editor:

  1. Create a target definition file, add your p2 repository, and select any feature from that p2 repository. Save the file.
  2. Open the target file in a text editor, remove the <unit> entry for the feature you added.
  3. Instead, add an entry for each of your bundles:

    <unit id="a.bundle.symbolic.name" version="0.0.0"/>
    

This target file then contains the latest version of each of the listed bundles. To see the content, open the file with the "Target Editor" again and switch to the "Content" tab. This file can now be used by all developers.

Note: When a new version of one of the bundles is deployed to Nexus, the developers will only see that new version if they open the target file and choose "Set as Target Platform" again.

Disproportion answered 20/9, 2013 at 9:0 Comment(0)
O
6

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!

Outburst answered 12/9, 2013 at 14:36 Comment(2)
I already had the Tycho Project Configurators installed... I retrieved them from http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-tycho/0.6.0/N/0.6.0.201207302152/ (as seen in the ''Install new software'' screen). When following your steps, the Tycho configurator are not (no longer?) present in the list.Occasion
Yes, I assume the list won't show software that's already installed. I'll have a look at some different setups I have, see if I find anything useful...Outburst
D
5

The "most automated" way to configure your target platform in Eclipse is to use a target file. That file can be checked in with your sources, so every developer only needs to open the file and click on "Set as Target Platform" to activate it. AFAIK there is no m2e connector or Eclipse plug-in which does that automatically.

Given your development process, setting up this target file is a little more tricky. Since you don't have a feature which contains the latest version of all your bundles, you need to include the bundles directly in the target file. This is not possible via the rich editor, but can be done with a text editor:

  1. Create a target definition file, add your p2 repository, and select any feature from that p2 repository. Save the file.
  2. Open the target file in a text editor, remove the <unit> entry for the feature you added.
  3. Instead, add an entry for each of your bundles:

    <unit id="a.bundle.symbolic.name" version="0.0.0"/>
    

This target file then contains the latest version of each of the listed bundles. To see the content, open the file with the "Target Editor" again and switch to the "Content" tab. This file can now be used by all developers.

Note: When a new version of one of the bundles is deployed to Nexus, the developers will only see that new version if they open the target file and choose "Set as Target Platform" again.

Disproportion answered 20/9, 2013 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.