Building an Eclipse plugin

Note that this feature is considered as experimental. It should work with simple configuration but may not in complex ones. If you have any issue with that feature, you are welcomed to come discussed your use case on the ivy-user mailing list, or discuss about implementation issues or improvement you may have found on ant-dev.
This page describes how to build an Eclipse™ plugin with Apache Ivy™ and its OSGi™ capabilities.

Quick setup

In few steps, we will setup a build to compile and package an Eclipse plugin.

  1. download this ivy.xml, this ivysettings.xml, this, this build.xml, and put them into your plugin folder;
  2. in the, specify the location of the plugins folder of your Eclipse target;
  3. in the ivy.xml, change the symbolic name declared in the extends element;
  4. (optional) by default the build.xml is expecting the sources to be in the src folder. You may want to edit it if it is not the case
  5. (optional) if Ivy is not in Ant's classpath, get the jar of Apache Ivy and edit the build.xml accordingly (see the comments at the begining of the file)
And that's it ! Now let's use it.

First, Ivy needs to aggregate the OSGi metadata of the target platform. To do so just launch:
ant buildobr
You need to run that command only once. Or each time your target platform get modified.

Then to resolve and build, just run:
ant build

Eclipse setup

You probably have already configured your project in Eclipse via the PDE. Let's see how to chnage that and use Apache IvyDE.

  1. so first remove from your project's classpath the PDE dependencies container;
  2. then right click on the ivy.xml you just added and select "Add Ivy library";
  3. in the configuration panel of the IvyDE classpath container, as the settings file put '${workspace_loc:mypluginproject/ivysettings.xml}';
  4. click finish and your Eclipse project should build now.
Nota Bene: to be resolved correctly Ivy is relying on the aggregated metadata of your target platform. Even if you want to only build with Eclipse, you will have to run the command ant obrindex at least one time.

Details on the setup

The repository

When building an Eclipse plugin, we are relying on a "target platform", the Eclipse installation we want our plugin to be eventually installed into. For Ivy, this will represent the repository of artifacts.

Ivy needs an aggragation of the OSGi metadata in order to resolve a such repository. The Ant task buildobr build a OBR (OSGi Bundle Repository) descriptor file from a set of OSGi bundles. So here we are using this Ant task to gather OSGi metadata from the Eclipse plugins in the "target platform". In the above exemple, the file is build in target/repo-eclipse.xml.

The plugin to be build has then a ivy.xml file describing its depedencies to be used by Ivy. Since the actual depedencies are in the MANIFEST.MF file, in the ivy.xml file we specify that it extends META-INF/MANIFEST.MF. So there not much dependencies specified in the ivy.xml. But as Ivy doesn't support the Bundle-Fragment OSGi feature, the ivy.xml can help specify the missing dependencies.

Having this setup, it is then a standard Ant+Ivy build. Ivy computes the classpath to be then used by the javac tasks. Note that javac is not aware of the OSGi metadata and is then incapable of failing to compile if private packages are accessed.