Version 7, last updated by HRJet at 14 May 06:01 UTC

Eclipse Plugin Development using the Scala IDE

These are the steps required if you'd like to use the Scala IDE for Eclipse for your plugin development.

1. Create a normal Java plugin project

I assume you have a normal Java plug-in which you want to extend with Scala code. If you want to create a Scala-only plug-in, you can of course always start with an empty, normal Java plug-in.

2. Configure the project for Scala

You can configure the project automatically or manually:

2a. Automatically add the Scala nature to the project

Right click on the project in the Package Explorer and then select Configure => Add Scala Nature. This will update the .classpath and .project files correctly, and will add scala.library to the required bundles for the plugin.

2b. Manually adapt the .project, .classpath and required bundles

To make the eclipse IDE aware of the Scala code, you have to update the .classpath and the .project files.

If you do it manually, in the .classpath, you have to add the Scala container.To make the running Eclipse plug-in aware of Scala, you have to do one more adaptation. Your manifest file needs to refer to scala.library in its require bundle section:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
	<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="src" path="src-gen"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

The .project file should look as follows (Scala builder, Scala nature). Note that the Java builder has been removed, since it is automatically invoked by the Scala builder.

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>de.itemis.oo</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.pde.ManifestBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.pde.SchemaBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.pde.PluginNature</nature>
	</natures>
</projectDescription>

At this point, you should be able to mix scala and Java sources. Specifically, you should be able to call scala code from Java code (instantiation, method calls).

Note that with versions of the Scala IDE <= 2.7.5.final the Eclipse Java editor might flag references to Scala entities as errors in the left margin of the editor, but not in the Problems view. This is an issue with the JDT integration which will be fixed for 2.8.0. Calling the methods at runtime, however, works.

Require-Bundle: all.kinds.of.things,
 scala.library

That's it.

3. Deployment

Update: As of 14 May 2012 and Scale IDE 2.1 M1

You can define Eclipse Features based on plugins written in Scala as usual. There are three ways to publish them.

a. Using PDE tool

Creating a P2 update site with PDE is problematic because generated class files are not included in the plugin.jar. This can be worked around with the help of an ant script.

b. Using Buckminister

A much better and recommended approach is to use Buckminster. It works out of the box, even with plugins written in Scala. Here's a quick guide to publish a p2 update site with Buckminster:

  • Install the Buckminster plugins into Eclipse from here. You will need both the Core and PDE support feature.
  • Create a new feature project that includes all the features you want to publish into your update site. Note that this feature itself is not exported, it only serves as a meta feature.
  • Create a properties file named, say, buck.properties. In it set the output directory for Buckminster and other settings. An example:
    buckminster.output.root=${user.home}/work/buckminster_out/

    #Should source bundles be built and included
    cbi.include.source=false
  • Right click on this feature project in project explorer, choose Buckminster -> Invoke Action, then choose the "site.p2". Specify the property file created above.
  • The update site should now be generated in the "buckminster.output.root" folder.

c. Using Tycho

 For those using Maven as a build tool, Tycho is an excellent option for building plugins, features, update sites, RCP applications and OSGi bundles.

Sample Plugin projects

(...written in Scala)

 Moodmetrics Plugin
~700 LOC in Scala.
The plug-in generates the metrics only for Java projects - it won't work for other languages. I guess I could somehow use Scalify so metrics could be generated for Scala projects ... ? BTW. if you've managed to get Scalify working on Linux, please list the steps taken.
 Pomodoro4Eclipse  A timer plugin for Eclipse intended for use with the Pomodoro Technique.
 ScalaStyle Plugin
 Check style of Scala code in Eclipse