Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Tycho/FAQ"
(→How to build plugin-based products with platform-specific fragments?: filters in products are no longer used (see bug 342890)) |
(deleted product-FAQ completely because the problem making it a FAQ has been resolved) |
||
Line 55: | Line 55: | ||
<properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties> | <properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties> | ||
</compilerArguments> | </compilerArguments> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</configuration> | </configuration> | ||
</plugin> | </plugin> |
Revision as of 05:50, 18 March 2013
See also the Frequently asked Tycho questions on stackoverflow.com.
Contents
- 1 Compilation
- 1.1 How do I embed a configurable build version?
- 1.2 How to configure warning/error settings of the OSGi compiler?
- 1.3 How to compile pre-processed source placed in a different directory?
- 1.4 How do I include rootfiles?
- 1.5 How should I define the target platform of my tycho project?
- 1.6 What other options does the Tycho compiler support?
- 1.7 Can I use the Tycho compiler support in non-OSGi projects, too?
- 2 Packaging
- 3 Testing
- 3.1 How to configure HTTP proxy settings during test execution?
- 3.2 How to use SWTBot or some UI tool for testing?
- 3.3 How do I add OS-specific flags?
- 3.4 How to add a undeclared dependency? (e.g., OSGi declarative service)
- 3.5 How to test OSGi declarative services?
- 3.6 How do I enable assertions during testing?
- 3.7 How can I debug my tests?
- 4 Diagnosing Build Problems
- 5 Documentation
Compilation
How do I embed a configurable build version?
To cause your artifacts to be branded with the a build number, modify your manifests (MANIFEST.MF, feature.xml, etc.) to specify the version as X.Y.Z.qualifier, and the corresponding pom.xml with X.Y.Z-SNAPSHOT. Tycho will replace the qualifier and SNAPSHOT with the build timestamp (in UTC).
You can set the build qualifier to a custom value by setting the forceContextQualifier property. For example:
mvn -DforceContextQualifier=M01 install
You can also set the qualifier by configuring the tycho-packaging-plugin, using some format supported by Java's SimpleDateFormat:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-packaging-plugin</artifactId> <version>${tycho-version}</version> <configuration> <format>'myprefix_'yyyyMMddHHmm</format> </configuration> </plugin>
Tycho does not directly support embedding the build identifier in resources. But some workarounds have been suggested in an email thread on tycho-user.
How to configure warning/error settings of the OSGi compiler?
To configure warnings:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-compiler-plugin</artifactId> <version>${tycho-version}</version> <configuration> <compilerArgument>-warn:[+|-]warning_tokens_separated_by_comma</compilerArgument> </configuration> </plugin>
The available warning tokens are listed in the Eclipse help. Same applies for the
-err
argument for configuring errors.
Alternatively, if you have per-project JDT preferences, you may advise the compiler to use these:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-compiler-plugin</artifactId> <version>${tycho-version}</version> <configuration> <compilerArguments> <properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties> </compilerArguments> </configuration> </plugin>
How to compile pre-processed source placed in a different directory?
Configure your pom.xml with something like the following:
<build> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-compiler-plugin</artifactId> <version>${tycho-version}</version> <configuration> <source>${project.basedir}/YourNewSourceDirectory</source> <usePdeSourceRoots>false</usePdeSourceRoots> </configuration> </plugin> </build>
How do I include rootfiles?
Tycho provides partial support for PDE-style rootfiles. Rootfiles are associated and installed with a feature. See the TYCHO465RootFiles test for an example of using rootfiles.
A different approach is to use the maven-assembly-plugin to assemble a zip file. We do not have a worked example, but Kai Kreuzer documented his approach that was necessary prior to the introduction of rootfile support [1].
How should I define the target platform of my tycho project?
This question is answered here: Tycho/Target Platform
What other options does the Tycho compiler support?
Run this command to get a list of options for your version of Tycho:
mvn help:describe -Dplugin=org.eclipse.tycho:tycho-compiler-plugin -Ddetail
Or you can have a look at the Maven site for Tycho.
Can I use the Tycho compiler support in non-OSGi projects, too?
When compiling regular maven projects (e.g., packaging "jar") the plugin tycho-compiler-jdt
can be used to tell maven to use the JDT compiler (aka "Eclipse Compiler for Java(TM)", "ecj") for compilation. This is useful to ensure that compilation in the IDE and on the build server show the same compiler messages, specifically JDT's annotation-based null analysis can be integrated into the build in this way.
Use the following snippet in your build.pluginManagement.plugins
section:
<plugin>
<!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>jdt</compilerId>
<compilerArgument>-err:nullAnnot,null</compilerArgument> <!-- insert your warn/err configuration here -->
</configuration>
<dependencies>
<!-- This dependency provides the implementation of compiler "jdt": -->
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>${tycho-version}</version>
</dependency>
</dependencies>
</plugin>
Again, a build.plugins.plugin.configuration.compilerArguments.properties
element can be used to reference an existing org.eclipse.jdt.core.prefs
file (see above).
Packaging
How to generate Eclipse-SourceReferences MANIFEST header?
See docs. Example for git:
<properties> <tycho.scmUrl>scm:git:https://git.eclipse.org/r/p/egit/egit.git</tycho.scmUrl> </properties> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-packaging-plugin</artifactId> <version>${tycho-version}</version> <configuration> <sourceReferences> <generate>true</generate> </sourceReferences> </configuration> <dependencies> <dependency> <groupId>org.eclipse.tycho.extras</groupId> <artifactId>tycho-sourceref-jgit</artifactId> <version>${tycho-extras-version}</version> </dependency> </dependencies> </plugin>
This will add the Eclipse-SourceReferences header including commit ID used for this build and tag (if present).
Testing
How to configure HTTP proxy settings during test execution?
Two options:
Manually configure the proxy
<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <configuration> <argLine>-Dhttp.proxyHost=myproxy -Dhttp.proxyPort=1234</argLine> </configuration> </plugin> </plugins> </build>
and disable the eclipse system proxy setting
if (Platform.isRunning() && getProxyService() != null && getProxyService().isSystemProxiesEnabled() && !getProxyService().hasSystemProxies()) { // XXX e3.5/gtk.x86_64 activate manual proxy configuration which // defaults to Java system properties if system proxy support is // not available getProxyService().setSystemProxiesEnabled(false); getProxyService().setProxiesEnabled(true); }
- or -
Make sure the native org.eclipse.core.net.* fragment for your platform is included in the test runtime so eclipse will pick up proxy settings configured on OS level:
<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <configuration> <dependencies> <dependency> <type>p2-installable-unit</type> <artifactId>org.eclipse.core.net.[YOUR_PLATFORM]</artifactId> <version>[VERSION]</version> </dependency> </dependencies> </configuration> </plugin> </plugins> </build>
How to use SWTBot or some UI tool for testing?
You need to configure the tycho-surefire-plugin to use the UI:<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <configuration> <useUIHarness>true</useUIHarness> <useUIThread>false</useUIThread> <argLine>-Xms40m -Xmx512m</argLine> </configuration> </plugin> </plugins> </build>
useUIHarness=true ensures the workbench is started before the tests are run. If your app requires a custom application class (viz the org.eclipse.core.runtime.applications extension point), you will likely need to configure the application.
You may wish to add --launcher.suppressErrors to the <appArgLine> element to suppress Eclipse error dialogs.
How do I add OS-specific flags?
Some OS's may require special flags (e.g., SWT on MacOS X). The easiest way is to use a Maven profile to configure a property. For example:
<properties> <os-jvm-flags/> <!-- for the default case --> </properties> <build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <version>${tycho-version}</version> <configuration> <useUIHarness>false</useUIHarness> <useUIThread>true</useUIThread> <argLine>-Xms40m -Xmx1G ${os-jvm-flags}</argLine> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>macosx-jvm-flags</id> <activation> <os><family>mac</family></os> </activation> <properties> <os-jvm-flags>-XstartOnFirstThread</os-jvm-flags> </properties> </profile> </profiles>
Alternatively you could configure the surefire plugins within a profile too.
How to add a undeclared dependency? (e.g., OSGi declarative service)
Use the tycho-surefire-plugin <dependencies> section (see the eclipse-test-plugin packaging type for an example).
How to test OSGi declarative services?
You need to add bundle org.eclipse.equinox.ds to the test runtime:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <configuration> <dependencies> <dependency> <type>p2-installable-unit</type> <artifactId>org.eclipse.equinox.ds</artifactId> </dependency> </dependencies> </configuration> </plugin>
How do I enable assertions during testing?
Add an <argLine> to the tycho-surefire-plugin's configuration:
<build> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <version>${tycho-version}</version> <configuration> <argLine>-ea</argLine> </configuration> </plugin> </plugins> </pluginManagement> </build>
How can I debug my tests?
Add -DdebugPort=8000 to your Maven commandline and attach a remote debug session.
See the docs http://www.eclipse.org/tycho/sitedocs/tycho-surefire/tycho-surefire-plugin/test-mojo.html#debugPort
Diagnosing Build Problems
What does Tycho's message "XXXX" mean?
See the Tycho Messages Explained page.
My build fails with a ClassCastException of a Tycho class. What is wrong?
ClassCastExceptions indicate that different Tycho versions are used in the same reactor. This is not supported. The problem typically occurs if some of the modules use the incorrect parent POM, e.g. an older version of the correct parent. Check the parent configuration in all modules of the reactor.
How to switch on eclipse tracing during test execution?
Eclipse has a platform tracing mechanism which is switched on by using commandline option -debug and configured by putting a file named .options into the installation root. You can enable this tracing mechanism for tycho test executions by running the build in debug mode using commandline option -X and putting a file .options inte the test project root.
E.g. a file .options with content
org.eclipse.osgi/resolver/debug=true org.eclipse.osgi/resolver/wiring=true
will switch on equinox wiring tracing.
Why is my app not working?
Many people post to tycho-user when they are encounter problems attempting to run their deployed applications, where the apps are missing icons, or throwing ClassNotFoundException and NoClassDefFoundError exceptions. Most of these problems are traced to errors in the projects' OSGi/p2 metadata. Some common issues are:
- a bundle declares a runtime dependencies as optional, but the dependency is actually not optional;
- the build.properties does not include some key directories or resources;
- the class files are not being bundled into a library, but the classpath does not include ".".
Tycho is not the cause of these issues, but Tycho does help "discover" these issues.
Sources of help:
- The PDE FAQ, particularly the section on Build and Deployment Errors.
- Tips on diagnosing bundle load failures.
How do I disable P2 mirrors?
Often times eclipse.org redirects P2 repository requests to a misconfigured/broken/unavailable P2 mirror repository and builds fail because of that. To disable use of P2 mirrors and force all downloads to go directly to the main repository specify the following maven command line parameter
-Dtycho.disableP2Mirrors=true
Documentation
Where can I find the Maven generated documentation for the Tycho plug-ins?
The documentation is available at:
http://www.eclipse.org/tycho/sitedocs/
and
http://www.eclipse.org/tycho/sitedocs-extras/
For more info see Tycho/Reference_Plugin_Docs.