Mirko Stocker

Building Eclipse Plug-ins Written in Scala with Maven/Tycho

The Scala Refactoring project currently uses a rather crude hand-written ant build file; it compiles and runs tests. What it doesn’t do is creating a proper OSGi bundle, which I need if I want to do proper releases and integrate it into the Scala Eclipse IDE. Most of my colleagues are using PDE build, but from what I’ve heard, Buckminster or Maven/Tycho are the way to go.

Buchminster looks rather complex to me, so I went with Maven, even though I had no prior experience with it. Now, a few hours later, I have a Hello World plug-in written in Scala and a bunch of poms that build everything I want, even an update site!

Tycho needs Maven 3, which hasn’t been released yet, so I downloaded the latest alpha build and created an alias that pointed to the mvn binary.

I started with Mattias Holmqvist’s Blog where he explains how to create the initial Maven configuration and an OSGi bundle in Eclipse (I created a Hello World Plug-in Project). Now, we don’t want to have a Java plug-in but one written in Scala, so I added the Scala Nature to the project and re-wrote the two generated files in Scala.

To add Scala functionality to my pom, I followed the Eclipse Scala Maven Integration wiki. I also had to add the Scala Eclipse Plug-in nightly build update site to my list of repositories so Maven could resolve the scala.library dependency the project has.

    <repository>
       <id>scala eclipse nightly</id>
       <layout>p2</layout>
       <url>http://download.scala-ide.org/scala-eclipse-toolchain-osgi-2.9.1.final/</url>
    </repository>

Because I apparently didn’t follow Maven’s source layout, I had to explicitly specify the source directory via:

<sourceDirectory>${basedir}/src</sourceDirectory>

Adding the update site and feature projects was a peace of cake when following this tutorial (scroll to Creating an Update Site / P2 repository) from the Tycho project.

I’ve put the whole project on GitHub so you can try it yourself. And remember, this is my first day with Maven, so if I could make the poms even smaller or more idiomatic, please tell me. Or even better, just fork my code!

Next I’m going to find out how to run unit tests and how the integration in Hudson works, and then I can migrate the Scala Refactoring project and delete a build.xml file.

Update April 2012: I’ve updated the sample repository to the latest versions of Scala, Eclipse and Maven-Tycho.

Update July 2012: Updated the sample repository to the use Scala 2.9.2, Eclipse Juno and Tycho 0.15.0.

6 Comments

  1. Hi Mirko

    Nice that you finally arrived with Maven 🙂
    It was a pleasure to read this blog and have a look at the maven stuff.
    I am very looking forward to hear more…

  2. Hey, I’m playing around with Maven, Tycho and Scala and have no success getting it to work all together. I’m an absolut Scala “Noob” which might also be one of the problems 🙂

    By googling this topic I stumbled over your article which seems exactly what I want to achieve. Some time has passed since you originally wrote it and sadly I have trouble getting your example build job to run. Is there any possibility that you update your tutorial? It would really help me and I believe many others too 🙂

  3. Hi Sebastian,

    I’m glad to hear that my post was helpful, I’ve update the sample repository to the latest versions of Scala/Eclipse/Tycho. Thanks for reporting this!

    Cheers, Mirko

  4. Hi Mirko,
    I am playing around with your example and everything is working fine. However I want to use latest versions of tycho (0.15.0), Eclipse Juno and scala (0.9.2). For tycho/juno this is working fine but for scala I have tried various update sites of scala ide but am not gettting any success.

    Can you give me a hint how I can use Scala 2.9.2 with this example?

    Thanks David

  5. got it you can drop the dependency to scala and add a configuration to the maven-scala-plugin:

    ${scala.version}

Leave a Comment