Remove SNAPSHOT and Qualifier in Maven/Tycho Builds

Before releasing Maven artifacts, you remove the-SNAPSHOTfrom your POMs. If you develop Eclipse projects and build with Maven and Tycho, you have to keep the versions in the POMs and the versions in MANIFEST, feature.xml and other Eclipse project artifacts consistent. Typically when you release an Eclipse p2 site, you don’t remove the.qualifierin the versions and you will get Eclipse bundles and features versions automatically processed: the .qualifer is replaced with a timestamp. But if you want to release some Eclipse bundles also as Maven artifacts (e.g., to Maven central) you have to remove the -SNAPSHOT before deploying (or they will still be considered snapshots, of course 🙂 and you have to remove .qualifier in Eclipse bundles accordingly.

To do that, in an automatic way, you can use a combination of Maven plugins and oftycho-versions-plugin.

I’m going to show two different ways of doing that. The example used in this post can be found here:https://github.com/LorenzoBettini/tycho-set-version-example.

First method

The idea is to use the goalparse-versionof theorg.codehaus.mojo:build-helper-maven-plugin. This will store the parts of the current version in some properties (by default,parsedVersion.majorVersion,parsedVersion.minorVersionandparsedVersion.incrementalVersion).

Then, we can pass these properties appropriately to the goalset-versionof theorg.eclipse.tycho:tycho-versions-plugin.

This is the Maven command to run:

The goal set-versionof the Tycho plugin will take care of updating the versions (without the -SNAPSHOT and .qualifier) both in POMs and in Eclipse projects’ metadata.

Second method

Alternatively, we can use the goal set(with argument-DremoveSnapshot=true) of theorg.codehaus.mojo:versions-maven-plugin. Then, we use the goalupdate-eclipse-metadataof theorg.eclipse.tycho:tycho-versions-plugin, to update Eclipse projects’ versions according to the version in the POM.

This is the Maven command to run:

The first goal will change the versions in POMs while the second one will change the versions in Eclipse projects’ metadata.

Configuring the plugins

As usual, it’s best practice to configure the used plugins (in this case, their versions) in the pluginManagementsection of your parent POM.

For example, in the parent POM ofhttps://github.com/LorenzoBettini/tycho-set-version-examplewe have:

 

Conclusions

In the end, choose the method you prefer. Please keep in mind that these goals are not meant to be used during a standard Maven lifecycle, that’s why we ran them explicitly.

Furthermore, the goal setof theorg.codehaus.mojo:versions-maven-pluginmight give you some headache if the structure of your Maven/Eclipse projects is quite different from the default one based on nested directories. In particular, if you have an aggregator project different from the parent project, you will have to pass additional arguments or set the versions in different commands (e.g., first on the parent, then on the other modules of the aggregator, etc.)

Leave a Reply

This site uses Akismet to reduce spam.Learn how your comment data is processed.