Search code examples
tycho

Optional dependency of host is not available in fragment


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.


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.