Using maven to handle Eclipse plug-in dependencies

Horacio Hoyos Rodriguez
3 min readFeb 6, 2019

Update March 2021: If you are using a target platform for your builds, you now use maven repositories as “content” providers in your target definition as explained here.

Dependency management has become the bread-and-butter of software development. As we push the boundaries of “reinventing the wheel”, we often found ourselves relying on a hefty amount of 3rd party libraries and with them, their dependencies. Having to find, download and manage these dependencies is such a difficult and time-consuming task that for most (if not all) general purpose languages there exist some version of a dependency management system. When developing Eclipse plug-ins, things get a bit trickier.

The Eclipse architecture is built around the concept of plugins. Plugins that, exploiting the OSGI module system, allow Eclipse applications to gain functionality by adding/installing plugins. Further, the Eclipse architecture also uses the plugin system to provide dependency management. That is, a plugin can list its dependencies as a list of other plugins. An Eclipse application can search for the required plugins (dependencies) in p2 repositories. For completeness, one can instruct the Eclipse application on what p2 repositories it should use for its search.

Plugins are basically packaged Java applications, i.e. when Eclipse downloads a plugin it downloads a jar file. However, not all jars can be used as plugins. For a Java application to be a plugin it must contain some specific files. As a result, we can not download a jar from a 3rd party library’s website, or maven for that matter, and use it as a plugin. Similarly, Eclipse can not install libraries from maven repositories. Although some popular libraries make it to the Orbit project (becoming available as regular plugins), not all of them do, or they might not provide the specific version you are looking for.

It is possible to create plugins from a jar, but this leads back to dependency hell as you would need to create separate plugins for each library in your dependency tree.

I have built a plugin scaffold that allows you to provide your required dependencies via maven. The scaffold is available here if you want to take a look as I explain how it works. It uses a pom to list all dependencies, as a regular maven project and employees the maven-dependency-plugin copy-dependencies goal to get a copy of all the jars from the dependency tree. The scaffold provides a script that loops over the downloaded jars and produces the required classpath entries so the Eclipse plugin facet of the project becomes aware of the jars.

For example, I want to use the ArangoDB Tinkerpop driver in order to allow a plugin to access an ArangoDB database via Tinkerpop. I download the scaffold, modify the MANIFEST and pom files with my project information and then add the required dependency:

<dependencies>
<dependency>
<groupId>org.arangodb</groupId>
<artifactId>arangodb-tinkerpop-provider</artifactId>
<version>${arango.provider.version}</version>
</dependency>
</dependencies>

After running mvn clean install the lib folder looks like this (not all jars shown):

Next, I run the included UpdateClasspathWithMavenDeps script. In the script folder you will find both a Unix and a Windows version. This will generate the jarEntries.tmp file with the following content:

<classpathentry exported=”true” kind=”lib” path=”lib/arangodb-java-driver-5.0.0.jar” sourcepath=”lib/arangodb-java-driver-5.0.0-sources.jar”/>
<classpathentry exported=”true” kind=”lib” path=”lib/arangodb-tinkerpop-provider-2.0.1.jar” sourcepath=”lib/arangodb-tinkerpop-provider-2.0.1-sources.jar”/>
<classpathentry exported=”true” kind=”lib” path=”lib/commons-collections-3.2.2.jar” sourcepath=”lib/commons-collections-3.2.2-sources.jar”/>
...

Note that if the source jars are available, they have been used to add a sourcepath to the classpath entries. Copy the contents of this file and paste them in the .classpath file in your project.

Don’t modify the scripts to change the .classpath file directly, eclipse does not like it and your project will break. You’ve been warned.

Finally, open you MANIFEST.MF file and in the Runtime tab add all the packages you want to make available to your other/dependent plugins. Then you can add this dependencies project to the other plugins that need it.

On a final note, remember that if your project is an Eclipse project, all the 3rd libraries you use have to be IP approved.

--

--