I have a project for which I have to create a new release from time to time. At the moment we have no facilities in place to increase the version numbers automatically (e.g. maven-release-plugin). Therefore I have to increase the version numbers manually (e.g. from 1.0.6 to 1.0.7).

For this task I prefer using GNU command line tools instead of an IDE (e.g. Eclipse or IntelliJ IDEA) for various reasons:

  • The project consists of many sub-projects and I don’t always have all the sub-projects opened in the IDE.
  • I can use the GNU command line tools on all OS platforms. When you are a developer and you are using Windows I heavily suggest that you install Cygwin. Cygwin enables you to use all sorts of GNU command line tools under Windows.
  • Sometimes I have projects where I don’t use an IDE at all.

At first I search for all occurences of the current version number to see where I will have to increase it:

$ egrep -Hir '1\.0\.6' | less

Then I run the following command to do the actual replacement:

$ find . -not \( -path ./.git -prune \) -type f \
    -iregex ".*\.\(MF\|xml\|e4xmi\|java\|product\)" \
    -print0 | xargs -0 sed -i 's/1\.0\.6/1.0.7/g'
  • We don’t want sed (the GNU Stream Editor which does the actual replacement) to mess around with the .git folder under any cirumstances. Therefore we exclude it from the search results (-not \( -path ./.git -prune \)). To read more about the different ways of how to exclude certain directories from a find search see here. The method above should work under any circumstances.
  • We don’t want sed to search for version number strings in e.g. binary files (egrep omits binary files by default). Therefore we only include files with certain file extensions in the search results (-iregex ".*\.\(MF\|xml\|e4xmi\|java\|product\)").

To review the changes made by sed I use the following command (see here for an exaplanation and possible variants):

$ git diff --color-words=.

This way you can easily spot the changed characters:

Example output of `git diff --color-words=.`.

Example output of `git diff --color-words=.`.

Example output of `git diff` when omitting the `--color-words=.` option.

Example output of `git diff` when omitting the `--color-words=.` option.

A note about Netcup (advertisement)

Netcup is a German hosting company. Netcup offers inexpensive, yet powerfull web hosting packages, KVM-based root servers or dedicated servers for example. Using a coupon code from my Netcup coupon code web app you can even save more money (6$ on your first purchase, 30% off any KVM-based root server, ...).