Building an Eclipse Project with Tycho – Experience Report

Build engineering was and is quite a challenge for many of the projects I worked on. For pure Java projects I have often used Maven for building, but for Eclipse/OSGi-based it never really worked out well for us. One of the main reasons was that the information Maven requires to build an artifact (aka plugin/bundle) has significant overlap with what you provide in the manifest of a plugin/bundle in Eclipse/OSGi. So essentially you are required to keep both in sync. For some time Tycho has promised to solve this problem and I always wanted to give it a try. This blog post describes what I needed to do to get a Tycho-based build for the EMFStore project and the EMF Client platform project up and running. Hopefully this can provide you with some hints on how to get your build set up and how difficult you can expect it to get.

Step 1 – Getting started
Download Maven from Apache and create a working directory with the source of your plugins/bundles. Maven is able to download all required plugins (e.g. tycho) on first use, so the initial run of a maven build might take some time.

Step 2 – Generate the Maven POM files
A Maven POM file describes what is required to build an artifact/plugin/bundle and provides meta data such as a version number and a name. To get started we will generate this information from the existing manifests of our bundles. For each bundle we will have an individual POM and in addition, there will be one parent POM with a common configuration.

For the parent POM we create a directory in the EMFStore releng plugin. The name of this directory will be, by default, the name of the parent POM´s artifact ID. We go to that directory and run the Tycho POM generator plugin (see command below). The command specifies a group ID for all generated Maven artifacts (think of it as project name) and a version for the artifacts. The version is 0.9.0.SNAPSHOT since 0.9.0 is the current version in the bundles and SNAPSHOT is the Maven equivalent to a non-release build. It is important that these version numbers are synced in order to use the tycho-versions-plugin later. Since the plugins of EMFStore and EMF Client Platform are in six git repositories and are not all in sub-folders of the current folder, they have to be added with the parameter -DextraDirs.

mvn org.eclipse.tycho:tycho-pomgenerator-plugin:generate-poms -DgroupId=org.eclipse.emf.emfstore -Dversion=0.9.0-SNAPSHOT -DextraDirs=../../org.eclipse.emf.ecp.core,../../org.eclipse.emf.ecp.other,../../org.eclipse.emf.ecp.releng,../../org.eclipse.emf.emfstore.core,../../org.eclipse.emf.emfstore.other,../../org.eclipse.emf.emfstore.releng

The command scans the emfstore-parent folder and the folders specified in extraDirs for plugin and feature projects and generates the required POM including a parent POM in the current directory.

Step 3 – Adjust the generated POM files

The generated parent POM needs some adjustments. First, we need to specify the Tycho version to use for our build:

  <properties>
	<tycho-version>0.15.0</tycho-version>
  </properties>

Additionally we will configure the different Eclipse releases as profiles and select a default profile. We will use this to define our target platform:

<profiles>
	<profile>
  		<id>platform-galileo</id>
  		<activation>
    			<property>
      				<name>platform-version-name</name>
      				<value>galileo</value>
    			</property>
  		</activation>
  		<properties>
    			<eclipse-site>http://download.eclipse.org/releases/galileo</eclipse-site>
    			<platform-version>[3.5,3.6)</platform-version>
  		</properties>
	</profile>
	<profile>
  		<id>platform-helios</id>
  		<activation>
    			<property>
      				<name>platform-version-name</name>
      				<value>helios</value>
    			</property>
  		</activation>
  		<properties>
    			<eclipse-site>http://download.eclipse.org/releases/helios</eclipse-site>
    			<platform-version>[3.6,3.7)</platform-version>
  		</properties>
	</profile>
	<profile>
  		<id>platform-indigo</id>
  		<activation>
    			<activeByDefault>true</activeByDefault>
    			<property>
      				<name>platform-version-name</name>
      				<value>indigo</value>
    			</property>
  		</activation>
  		<properties>
    			<eclipse-site>http://download.eclipse.org/releases/indigo</eclipse-site>
    			<platform-version>[3.7,3.8)</platform-version>
  		</properties>
	</profile>
	<profile>
  		<id>platform-juno</id>
  		<activation>
    			<property>
      				<name>platform-version-name</name>
      				<value>juno</value>
    			</property>
  		</activation>
  		<properties>
    			<eclipse-site>http://download.eclipse.org/releases/juno</eclipse-site>
    			<platform-version>[3.8,3.9)</platform-version>
  		</properties>
	</profile>
  </profiles>

We can now also adjust the module section to remove plugins we don’t want to build.
We add the Eclipse update sites for the repositories using the profiles we defined before:

  <repositories>
	<repository>
  		<id>eclipse-platform</id>
  		<layout>p2</layout>
  		<url>${eclipse-site}</url>
	</repository>
  </repositories>

We then set the version of tycho-maven-plugin from 15.0.0 to the ${tycho-version} variable defined earlier and we set the bin folder as output directory:

<outputDirectory>bin</outputDirectory>

Finally we configure the target platform

<plugin>
    	<groupId>org.eclipse.tycho</groupId>
    	<artifactId>target-platform-configuration</artifactId>
    	<version>${tycho-version}</version>
    	<configuration>
      	<resolver>p2</resolver>
      	<pomDependencies>consider</pomDependencies>
      	<environments>
        	<environment>
          	   <os>linux</os>
          	   <ws>gtk</ws>
          	   <arch>x86</arch>
        	</environment>
        	<environment>
          	   <os>linux</os>
          	   <ws>gtk</ws>
          	   <arch>x86_64</arch>
        	</environment>
        	<environment>
          	   <os>win32</os>
          	   <ws>win32</ws>
          	   <arch>x86</arch>
        	</environment>
        	<environment>
          	   <os>win32</os>
          	   <ws>win32</ws>
          	   <arch>x86_64</arch>
        	</environment>
        	<environment>
          	   <os>macosx</os>
          	   <ws>cocoa</ws>
          	   <arch>x86_64</arch>
        	</environment>
      	</environments>
    	</configuration>
  	</plugin>

 

Step 4 – Configure update site

We need to create a new general project (in our case named org.eclipse.emf.emfstore.p2updatesite) to store the category definition. Inside the project we create a new Category Definition with the necessary categories (including categories for source features) and features. Since there is no POM for the category definition, we need to create a pom.xml in the same directory with this content:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
	<groupId>org.eclipse.emf.emfstore</groupId>
	<artifactId>emfstore-parent</artifactId>
	<version>0.9.1-SNAPSHOT</version>
	<relativePath>../emfstore-parent/</relativePath>
  </parent>
  <groupId>org.eclipse.emf.emfstore</groupId>
  <artifactId>org.eclipse.emf.emfstore.p2updatesite</artifactId>
  <version>0.9.1-SNAPSHOT</version>
  <packaging>eclipse-repository</packaging>
</project>

And, add the new plugin to the module section in the parent POM:

<module>../org.eclipse.emf.emfstore.p2updatesite</module>

 

Step 5 – Build it!

Now the update site can be built locally by executing mvn clean install from the emfstore-parent directory.
To build with Hudson, download and start Hudson and configure the git and Maven paths (Manage Hudson -> Configure System).
Then, create a new Maven job:

 Building an Eclipse Project with Tycho   Experience Report

Now, add the git repositories and specify root pom, goals and the files to archive:

 Building an Eclipse Project with Tycho   Experience Report

That’s it. Save the job and schedule a build!

Of course there is a lot more to do, and in my next blog I’ll write about the following topics:

  • Products – building products
  • Source Bundles – building source bundles for your plugins
  • Checkstyle – letting Checkstyle analyze your code
  • Running Tests
  • Test coverage – analyzing test coverage

A big thank you to Johannes Faltermeier for helping me with setting up everything!

Have fun with Maven and Tycho!

 

4 Responses to “Building an Eclipse Project with Tycho – Experience Report”

  1. Lars Vogel says:

    Did you migrate to CBI already?

  2. Maximilian Koegel says:

    No, not yet, this was a test drive to see how it would work for us to build with Maven.

  3. execc says:

    Hi!

    Have you setted up an automatic dependency resolition in Eclipse itself? I mean, to automate IDE configurationto resolve all the dependencies from Tycho target platform.

  4. Maximilian Koegel says:

    No, not yet, but I will consider this for the next blogs, thanks!

4 responses so far

Written by . Published in Categories: Planet Eclipse

Published:
Aug 26th, 2012
Follow:

Twitter Google+