bousson
bousson

Reputation: 774

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

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:

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!

Upvotes: 10

Views: 7125

Answers (2)

oberlies
oberlies

Reputation: 11723

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.

Upvotes: 5

s.d
s.d

Reputation: 4185

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!

Upvotes: 6

Related Questions