Articles

Locales vs. consistent builds

In General on 2008-07-31 by Jukka Zitting Tagged: , ,

[MOJO-1193] Locale support for formatting dates and times

I wanted to use the Maven buildnumber plugin to generate a date string like “31-Jul-2008” for inclusion in an automatically generated release notes document. This way I could minimize the amount of manual tweaking I need to do when publishing the release.

This was easy enough (though quite verbose) to achieve:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>buildnumber-maven-plugin</artifactId>
      <configuration>
        <format>{0,date,dd-MMM-yyyy}</format>
        <items>
          <item>timestamp</item>
        </items>
      </configuration>
      <executions>
        <execution>
          <phase>validate</phase>
          <goals>
            <goal>create</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

Unfortunately, the resulting date string would be the expected “31-Jul-2008” on one computer, but “31-heinä-2008” (in Finnish) on my laptop. Instead of changing the settings of my laptop I wanted to explicitly set the locale that the buildnumber plugin should use when formatting the date. I wasn’t too surprised that the required functionality didn’t yet exist (it’s quite common for people to forget about locales), but luckily it wasn’t too hard to add. Thus MOJO-1193.

With my patch the required configuration becomes:

      <configuration>
        <format>{0,date,dd-MMM-yyyy}</format>
        <locale>en_US</locale>
        <items>
          <item>timestamp</item>
        </items>
      </configuration>

Consistency is good.

Advertisements

3 Responses to “Locales vs. consistent builds”

  1. I’d argue that in this case, an ISO-8601 date format (which is locale-independant) would have been the better choice anway :-)

  2. Agreed. Unfortunately I was following an existing template, and changing the technology was easier than figuring out how set in stone the template is. ;-)

  3. I see. I expected there was a good reason :-)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: