Today Eclipse Tycho 4.0.11 was released which has some great additions for building bnd workspaces with Maven.
Features:
- See BND Workspace Layout and Pomless Builds
- requires almost zero configuration
- supports Export of executable
.jar
via a.bndrun
file
Really?
All you need is the following steps:
- Add a folder called
.mvn
to the root - Inside the
.mvn
folder place a file calledextensions.xml
with the following content:
?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>${tycho-version}</version>
</extension>
</extensions>
- create a file called
maven.config
in the.mvn
folder with the following content (adjust the Tycho version accordingly to the latest release!):
-Dtycho-version=4.0.11
You can now run your build with mvn clean verify
.
Export executable jar from .bndrun
If you want to create an executable jar from a .bndrun
, add:
-Dbndrun.exports=mydemo.app
to .mvn/maven.config
.
This automatically searches all your bundles for a file named mydemo.app.bndrun
.
If you have a bundle myappbundle
which contains mydemo.app.bndrun
, then the build would create an executable jar at the following location:
/myappbundle/target/executable/mydemo.app.bndrun.jar
Demo Project
This example shows how one can build a BND Workspace with Maven without any poms.
Bndtools Workspace Template Fragments
Also released today there are two new Workspace Template Fragments which you can use to setup your Bnd workspace in Eclipse via bndtools.
File / New / Bnd Workspace (Fragments)
At the bottom there are two maven-tycho-build
Templates containing the aformentioned .mvn folder.
- tycho/setup/bnd-templates/pomless at main · eclipse-tycho/tycho · GitHub
- tycho/setup/bnd-templates/pomless-configurator at main · eclipse-tycho/tycho · GitHub
The first is the simplest possible way, and the second uses a configurator pom.xml
which is needed if you want to add other maven plugins.
Replacing bnd gradle with maven based build via Tycho
My company has used it to fully replace a bnd gradle based build (via bnd workspace gradle plugin) with this Tycho maven based approach.
Why did we convert to Tycho?
The reasons why we switch are surely debatable, but in essence it was because:
- Maven seems pretty stable and we are not as confident about gradle in combination with the bnd workspace gradle plugin (here and here)
- The ecosystem around Tycho seems pretty active since Tycho is also used to build Eclipse Platform which is also OSGi based. So Tycho has OSGi in its DNA already and includes and uses
bndlib
for some time already. - the web is full of tutorials using Maven
- we have other stuff which uses maven, so we are happy to have one tool less to worry about
What about the bnd-maven-plugins? Why did we not use them?
We tried at first and played around. But we hit roadblocks, since it seemed, that the dependencies especially the -buildpath
has to be managed via pom.xml files.
This required a lot of ceremony (you need pom.xml files in each project and have to restructure a lot of stuff to match it).
But we basically just wanted to keep our existing bnd workspace with all the information already existing in build.bnd
, bnd.bnd
files and .bndrun
files.
Then Christoph @laeubi came around and mentioned Tycho’s bnd workspace support.
Tycho supports exactly that out of the box (since 4.0.11.
Last but not least I want to thank @laeubi for all the support during the last week.
He quickly added some small missing pieces e.g. bnd sub-bundles via -sub
instruction did not work and the export of executable jar files via .bndrun
. And we helped testing and he also discovered and fixed some bugs in bnd / bndtools during that process.
In this spirit:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:15 min
[INFO] Finished at: 2025-02-05T15:44:22+01:00
[INFO] ------------------------------------------------------------------------
Feel free to try it out and provide feedback.