Question

My host plugin declares an optional dependency to another plugin. In the build of a fragment to my host plugin, the optionally required plugin can't be found by Tycho. That means I get compile errors since the classes from the optional dependency can't be resolved.

If I remove the optional flag in host plugin, the Tycho build works fine. I'm using Maven 3.0.4 and Tycho 0.15.0.

Was it helpful?

Solution

I am undecided if this is really a bug in Tycho, or rather by design.

This is the background to the observable behaviour: Tycho aims to do its dependency resolution in the same way as p2 would do when installing your bundle. When you declare an optional dependency to a bundle, that bundle will not be installed by p2 (unless some other bundle or feature has a non-optional dependency to that bundle). So following this rule, Tycho would also not consider this optional dependency during dependency resolution and class path computation.

However, there is a switch to deviate from the default p2 behaviour (in target-platform-configuration the configuration option dependency-resolution/optionalDependencies):

  • With the value require, all optional dependencies of the current bundle are treated as required at compile time. Since this is what you normally want, this is the default.
  • With the value ignore, all optional dependencies of the current bundle are ignored at compile time.

Note that this special handling only applies to the optional dependencies of the current bundle, and not to other bundles in the dependency chain. Host bundles are currently treated as any other dependency, we may consider treating them specially when building a fragment.

You have the following options for a workaround:

  • Also add the optional dependency in the manifest of the fragment. The easiest way to do this is to use a text editor. Strictly speaking, this is the right thing to do: A fragment really should declare its own dependencies and not rely on declarations elsewhere. But since the PDE doesn't require you to do so, it is questionable if Tycho should.
  • Add an explicit compile-time only dependency in the fragment via the jars.extra.classpath option in the build.properties.

OTHER TIPS

I found a workaround. I removed the optional plugin in the host plugin and added it to the fragment via the Manifest-Editor. After that I readded it to the host plugin and declared it as optional again. (If the plugin is already declared in the host plugin you can't see it in the fragment via the add-Button of the Manifest-Editor) But I think this is a bug in tycho. Optional dependencies must also be available in the fragments as it is in eclipse.

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