dependency-managementp2tycho

Eclipse RCP built by Tycho includes unwanted optional dependencies


This is a question which has been frequently asked in the Tycho community:

I migrated my Eclipse RCP build from [previous technology, e.g. eclipse-application/ PDE headless build / ...] to the new recommended way of building products with Tycho using the packaging type eclipse-repository. Now my distribution contains more bundles than before.

The problem seems to be that Tycho pulls in the optional dependencies of the bundles included in my product. How can I prevent this?


Solution

  • Tycho's eclipse-repository packaging type builds product distributions with the same technology (called p2) you also use when, for example, installing a new feature into your Eclipse IDE. This has the advantage that, unlike with other build technologies, you don't need to manually specify all dependencies of the bundles you want in your product, but Tycho/p2 will automatically include them for you. (This is important because otherwise the bundles would not start at runtime.)

    On the other hand, this may also be a disadvantage: Tycho/p2 also includes certain optional dependencies that you would rather want to exclude from your product.

    There is no option to tell Tycho to not include any optional dependencies (because p2 doesn't have this option). However you can identify the optional bundles you don't want, and explicitly exclude them from the target platform with the following configuration:

    <plugin>
       <groupId>org.eclipse.tycho</groupId>
       <artifactId>target-platform-configuration</artifactId>
       <version>${tycho-version}</version>
       <configuration>
          <filters>
             <filter>
                <type>eclipse-plugin</type>
                <id>unwanted.bundle.id</id>
                <removeAll />
             </filter>
          </filters>
       </configuration>
    </plugin>
    

    Then the product build can no longer see the excluded bundle, and will omit it from the installation.

    Note: If you get a dependency resolution error after adding the above configuration, there is something that non-optionally requires the bundle. Although it is a bit tricky to read, the error message will tell you the chain of dependencies that leads from something you are building to the removed bundle.