Building an Eclipse Project with Tycho - Experience Report

August 26, 2012 | 4 min Read

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 diffi 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:

  
 0.15.0
  

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


    platform-galileo
    
       
          platform-version-name
          galileo
       
    
    
       https://download.eclipse.org/releases/galileo
       [3.5,3.6)
    
 
 
    platform-helios
    
       
          platform-version-name
          helios
       
    
    
       https://download.eclipse.org/releases/helios
       [3.6,3.7)
    
 
 
    platform-indigo
    
       true
       
          platform-version-name
          indigo
       
    
    
       https://download.eclipse.org/releases/indigo
       [3.7,3.8)
    
 
 
    platform-juno
    
       
          platform-version-name
          juno
       
    
    
       https://download.eclipse.org/releases/juno
       [3.8,3.9)

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:

  
    eclipse-platform
    p2
    ${eclipse-site}

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:

bin

Finally we configure the target platform


     org.eclipse.tycho
     target-platform-configuration
     ${tycho-version}
     
       p2
       consider
       
         
              linux
              gtk
              x86
         
         
              linux
              gtk
              x86_64
         
         
              win32
              win32
              x86
         
         
              win32
              win32
              x86_64
         
         
              macosx
              cocoa
              x86_64

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

4.0.0

org.eclipse.emf.emfstore emfstore-parent 0.9.1-SNAPSHOT ../emfstore-parent/

org.eclipse.emf.emfstore org.eclipse.emf.emfstore.p2updatesite 0.9.1-SNAPSHOT eclipse-repository

` And, add the new plugin to the module section in the parent POM:`xml ../org.eclipse.emf.emfstore.p2updatesite

``` `  

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:

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

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!

Join me on Google+

Maximilian Koegel

Maximilian Koegel

Dr. Maximilian Koegel is deeply involved with the Eclipse community. He is project lead and committer on several open-source projects including EMF Cloud, JSON Forms and …