2008-07-31...12:11

Locales vs. consistent builds

Jump to Comments

[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.

3 Comments

  • Julian Reschke

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

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

  • Julian Reschke

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


Leave a Reply