Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Tycho/Target Platform"

(Added Sample target file)
Line 56: Line 56:
 
* The location types "Directory", "Installation", and "Features" are not supported.
 
* The location types "Directory", "Installation", and "Features" are not supported.
 
* The selection on the Content tab of the Target Editor is ignored, i.e. it is not possible to de-select individual bundles for the Tycho target platform.
 
* The selection on the Content tab of the Target Editor is ignored, i.e. it is not possible to de-select individual bundles for the Tycho target platform.
 +
 +
===== Sample target file =====
 +
This is a sample target file for building a simple RCP application (see org.eclipse.tycho/tycho-its/projects/TYCHO188P2EnabledRcp/target-definition/helios.target).
 +
This uses the features "org.eclipse.rcp" and "org.eclipse.equinox.executable" which is all a simple RCP application needs.
 +
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 +
<?pde version="3.5"?>
 +
 +
<target name="eclipse 3.6.0">
 +
<locations>
 +
<location includeAllPlatforms="false" includeMode="planner" type="InstallableUnit">
 +
<unit id="org.eclipse.rcp.feature.group" version="3.6.0.v20100519-9OArFKvFtsd7WLUKh-DcYTS" />
 +
<unit id="org.eclipse.equinox.executable.feature.group" version="3.4.0.v20100524-7M7K-FIhIez-egBko15H73" />
 +
<repository location="http://download.eclipse.org/releases/helios/" />
 +
</location>
 +
</locations>
 +
</target>
 +
</pre>
 +
 +
Note the use of <tt>includeAllPlatforms="false"</tt>.  When this option is set to true it will result in all available environment specific plug-ins to be added to the target, rather than just the plug-ins that apply to your target's environment settings. See the [http://help.eclipse.org/indigo/topic/org.eclipse.pde.doc.user/guide/tools/target_shared/location_edit_site_wizard.htm eclipse docs].
 +
 +
If you are getting errors like:
 +
<pre>
 +
[ERROR] Internal error: java.lang.RuntimeException: Failed to resolve target definition .....target: "Problems resolving provisioning plan.": ["Unable to satisfy dependency from
 +
org.eclipse.equinox.executable.feature.group 3.5.1.v20111216-1653-7P7NFUIFIbaUcU77s0KQWHw5HZTZ to org.eclipse.equinox.executable_root.gtk.linux.ppc
 +
</pre>
 +
then it is likely you have <tt>includeAllPlatforms="true"</tt>
  
 
==== "POM dependencies consider" ====
 
==== "POM dependencies consider" ====

Revision as of 21:47, 17 April 2012

The target platform is the set of artifacts from which Tycho resolves the project's dependencies.

Background: OSGi allows to specify dependencies with version ranges and package dependencies (Import-Package). These dependencies (intentionally) do not map to unique artifacts. In order to pick a set of concrete bundles to be used for compilation, test execution, and assembly, Tycho needs a set of candidate artifacts which may be used to match the dependencies. This list of candidate artifacts is called the "target platform". The process of selecting artifacts from the target platform according to the project's dependencies is called "dependency resolution".

There are different ways to define the content of the target platform; the most common ones are repositories with layout=p2 in the POM, which add entire p2 repositories to the target platform, or target definition files for more fine-grained control.

Which approach should I use for the target platform for my project?

Since there are a few different ways to configure a target platform in Tycho, here are some rule of thumbs for the most common cases:

  1. If you are already using a target file in Eclipse, and that target file only contains location elements with type="InstallableUnit", use that target file for the Tycho build. In all other cases, it is not possible to share the target platform configuration between Tycho and Eclipse.
  2. If you don't care about individual bundles and versions, just configure the needed p2 repositories in the POM and have Tycho pick anything required from these repositories.
  3. If you want control over the which bundles/bundle versions are visible to the build, use a target file.

Target platform configuration

The target platform is defined through POM configuration (see details below). Each module has its own target platform, although with the normal configuration inheritance in Maven, the target platform configurations are usually the same across multiple modules.

Simple target platform configuration

In order allow Tycho to resolve the project dependencies against anything from a specific p2 repository, add that repository in the <repositories> section of the POM. Example:

<repository>
   <id>eclipse-indigo</id>
   <url>http://download.eclipse.org/releases/indigo</url>
   <layout>p2</layout>
</repository>

In terms of the target platform, this means that the entire content of the p2 repositories specified in this way become part of the target platform.

Background: In a normal (i.e. non-Tycho) Maven project, one can configure Maven repositories which can be used by Maven to resolve the project dependencies. While Maven repositories cannot be used directly (see below for an indirect approach), Tycho can use p2 repositories for resolving OSGi dependencies. The p2 repositories need to be marked with layout=p2. (The normal Maven dependency resolution ignores repositories with layout=p2.)

Target files

The PDE target definition file format (*.target) allows to select a subset of units (bundles, features, etc.) from one or more p2 repositories. In order to add the content of a target definition file (see "Content" tab of the Target Editor) to the target platform in the Tycho build, configure the target file in the target-platform-configuration build plugin. Example:

<plugin>
   <groupId>org.eclipse.tycho</groupId>
   <artifactId>target-platform-configuration</artifactId>
   <version>${tycho-version}</version>
   <configuration>
      <target>
         <artifact>
            <groupId>org.example</groupId>
            <artifactId>target-definition</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <classifier>targetFileNameWithoutExtension</classifier>
         </artifact>
      </target>
   </configuration>
</plugin>

The target definition file then needs to be placed in the root of project with the specified GAV.

Note: Tycho has only limited support for target definition files:

  • The location types "Directory", "Installation", and "Features" are not supported.
  • The selection on the Content tab of the Target Editor is ignored, i.e. it is not possible to de-select individual bundles for the Tycho target platform.
Sample target file

This is a sample target file for building a simple RCP application (see org.eclipse.tycho/tycho-its/projects/TYCHO188P2EnabledRcp/target-definition/helios.target). This uses the features "org.eclipse.rcp" and "org.eclipse.equinox.executable" which is all a simple RCP application needs.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.5"?>

<target name="eclipse 3.6.0">
	<locations>
		<location includeAllPlatforms="false" includeMode="planner" type="InstallableUnit">
			<unit id="org.eclipse.rcp.feature.group" version="3.6.0.v20100519-9OArFKvFtsd7WLUKh-DcYTS" />
			<unit id="org.eclipse.equinox.executable.feature.group" version="3.4.0.v20100524-7M7K-FIhIez-egBko15H73" />
			<repository location="http://download.eclipse.org/releases/helios/" />
		</location>
	</locations>
</target>

Note the use of includeAllPlatforms="false". When this option is set to true it will result in all available environment specific plug-ins to be added to the target, rather than just the plug-ins that apply to your target's environment settings. See the eclipse docs.

If you are getting errors like:

[ERROR] Internal error: java.lang.RuntimeException: Failed to resolve target definition .....target: "Problems resolving provisioning plan.": ["Unable to satisfy dependency from
org.eclipse.equinox.executable.feature.group 3.5.1.v20111216-1653-7P7NFUIFIbaUcU77s0KQWHw5HZTZ to org.eclipse.equinox.executable_root.gtk.linux.ppc

then it is likely you have includeAllPlatforms="true"

"POM dependencies consider"

OSGi bundles from Maven repositories can be added to the target platform in the following way:

  1. Specify a dependency to the OSGi bundle artifact in the POM's <dependencies> section.
  2. Set the configuration parameter pomDependencies=consider on the target-platform-configuration plugin

This configuration has the following effect:

  • First, Maven resolves the GAV dependencies according to the normal Maven rules. This results in a list of artifacts consisting of the specified artifacts and their transitive Maven dependencies.
  • Tycho then considers each of these artifacts for the target platform: if the artifact is an OSGi bundle, it is added to the target platform. Other artifacts are ignored. OSGi bundles which become part of the target platform in this way are then available to resolve the project's OSGi dependencies.

For an example, see the POM of this demo project.

Effective content of the target platform

In case multiple target platform configuration approaches are combined (which should be rarely necessary), the target platform contains the union of the content defined through each approach.

Apart from the explicitly configured content, the target platform also contains the following artifacts:

  • Other artifacts from the same reactor
  • Locally built artifacts in the local Maven repository

TODO Option to exclude locally built artifacts from the target platform (bug 355367)

Filtering

Since Tycho 0.14.0, it is possible to selectively remove content from the target platform. This for example allows to restrict the version of a bundle, or to select one particular provider for a package. Filtering is done as last step in the target platform computation, so the filters apply to all sources listed above.

The filters are specified in the target-platform-configuration build plugin:

<plugin>
   <groupId>org.eclipse.tycho</groupId>
   <artifactId>target-platform-configuration</artifactId>
   <version>${tycho-version}</version>
   <configuration>
      <filters>

         <!-- example 1: restrict version of a bundle -->
         <filter>
            <type>eclipse-plugin</type>
            <id>org.eclipse.osgi</id>
            <restrictTo>
               <versionRange>[3.6,3.7)</versionRange> <!-- alternative: <version> for selecting exactly one versions -->
            </restrictTo>
         </filter>

         <!-- example 2: remove all providers of the package javax.persistence except the bundle javax.persistence -->
         <filter>
            <type>java-package</type>
            <id>javax.persistence</id>
            <restrictTo>
               <type>eclipse-plugin</type>
               <id>javax.persistence</id>
            </restrictTo>
         </filter>

         <!-- example 3: work around Equinox bug 348045 -->
         <filter>
            <type>p2-installable-unit</type>
            <id>org.eclipse.equinox.servletbridge.extensionbundle</id>
            <removeAll />
         </filter>
      </filters>
   </configuration>
</plugin>

Notes:

  • The filters will only remove content from the target platform; they will not add new content. If you specify a restriction that is not fulfilled by any of the units from the target platform sources, all units that the filter applies to (i.e. units that match the filter.type, filter.id, and filter.version/versionRange criteria) will be removed from the target platform.
  • Package provider restrictions work by removing all other bundles exporting the package. This means that these other bundles (and the packages only exported by them) won't be available in your build.

Dependency resolution troubleshooting

TODO

Run mvn with "-Dtycho.debug.resolver=true -X" to see debug output.

This will debug

  • Properties
  • Available IUs
  • JRE IUs
  • Root IUs

Copyright © Eclipse Foundation, Inc. All Rights Reserved.