Automatic increase module version in a NetBeans Platform Based Application

Some time ago on the NetBeans-dev mailing list, a user asked how to automatically increment the version of a module when it is built. I remember doing something similar for work but in my case, the update was not automatic but was made when the suite was built.

The github link for the sample application is here.

The first attempt was to write the version as 1.0.20170417223643, the module compiled fine, but it won’t install because 20170417223643 does not fit an integer.

The second attempt was to write the version as 2017.0417.223643, which worked, however, this was not very good looking and I decided to just read the previous version and increase it.

I create an Ant Task that increased the version number; I also made certain that if the version of the module is not written in the manifest file but in the module properties, it would be updated as well.  This could happen when you declare implementation dependencies.

I gave a look at the README file inside the netbeans-8.2/harness to refresh my memory on how to customize the module build system.

IMHO the best place to increase the version number was the “nbm” target. This is the target that is called when the NBM file is constructed.

I overwrote the “nbm” with my own in this way:

<target name="nbm" depends="updateManifest, projectized-common.nbm">

“updateManifest” is the target that increases the version number, while “projectized-common.nbm” is the original that builds the nbms. The order of the dependencies makes sure that the two targets are called in the right order.

The “updateManifest”  looks like this:

<taskdef name="updatemanifest" classname="it.scantamburloenrico.dailymanifestant.UpdateManifestTask" >
 <fileset dir="${basedir}/../../dailymanifest/dailymanifestAnt/target" >
 <filename name="dailymanifestAnt-1.0-SNAPSHOT.jar" />

 <target name="updateManifest">
 <updatemanifest />

The taskdef at the beginning is needed to import the jar file that contains the task.

I used maven to create the ANT task, it just searches for the manifest file, if the task finds it then the version number is increased, otherwise, the task searches for the “spec.version.base” property inside the project properties and updates it.

The image comes from here

Leave a Comment

Your email address will not be published.

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