How to stop the p2 director from resolving optional dependencies for one of our plugins?

StackOverflow https://stackoverflow.com/questions/16038379

  •  04-04-2022
  •  | 
  •  

Question

We have a PDE build creating a big p2 repository. We skip the p2 director during the PDE build to call the p2.director on a specific feature (a sub-feature of what has been built).

The problem is that one of our plugins is having an optional dependency that we do not want to be satisfied, whereas all other optional dependencies should be satisfied. Is this possible?

Was it helpful?

Solution 2

I have finally manage to tell p2 to avoid looking for optionnal dependencies only in this plugin by creating a p2.inf file in the META-INF/ folder of the plugin.

the p2.inf is just telling that the optional imported package(s) is non greedy meaning it does not try to resolve this dependency.

Here is an example :

requires.0.namespace=java.package
requires.0.name=com.lowagie.text
requires.0.greedy=false
requires.0.optional=true
requires.1.namespace=java.package
requires.1.name=com.lowagie.text.exceptions
requires.1.greedy=false
requires.1.optional=true

OTHER TIPS

If you use a more recent version of the PDE headless build (or probably also any other build tool), all optional manifest dependencies will be translated to optional, non-greedy p2 dependencies (i.e. dependencies which are ignored when p2 resolves an installation plan.) The background here is that in version Juno M1, the p2 publishers were changed to generate optional, non-greedy p2 dependencies by default.

If you do in fact want an optional, greedy p2 dependency, you can either change the greediness via a p2.inf with requires.<n>.greedy=true, or by adding an x-installation directive in the MANIFEST.MF:

Import-Package: org.example;resolution:=optional;x-installation:=greedy

On a more general note, you should avoid optional, greedy p2 dependencies. The reason is that they may lead to surprising behaviour in your users' installations: If an optional, greedy dependency is originally not satisfied, and the user happens to use a p2 repository which contains the dependencies (e.g. to install something completely unrelated), the greedy dependencies would also be added to the installation. So with optional, greedy dependencies, installations may change "randomly" after adding a p2 repository to the list of available software site.

So instead, you should leave all dependencies as optional, non-greedy, and instead offer two feature which includes your plug-ins: one with and one without the the optional dependencies. In this way, you users have full control over whether they want the optional things installed or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top