Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Maven show local timezone in maven.build.timestamp?

In Maven 3.2.2+, the maven.build.timestamp has been redefined to show the time in UTC, as per MNG-5452.

Is there any way to specify that I want the timezone info in my local timezone and not in UTC? I briefly browsed the maven sources, but do not see anyway to specify that I want the TZ to be local TZ and not UTC based.

like image 625
Eric B. Avatar asked Feb 02 '15 16:02

Eric B.


People also ask

What is Buildnumber Maven plugin?

This plugin is designed to give you a build number. So when you might make 100 builds of version 1.0-SNAPSHOT, you can differentiate between them all.

What is a Maven POM file?

What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.


1 Answers

As already mentioned, in the current versions of Maven (at least up to version 3.3.+), the maven.build.timestamp property does not allow for timezone overrides.

However, if you are okay with utilizing a different property name for your purposes, the build-helper-maven-plugin allows you to configure custom timestamps for a variety of purposes. Here is an example to configure the current timestamp in EST during a build.

        <plugin>             <groupId>org.codehaus.mojo</groupId>             <artifactId>build-helper-maven-plugin</artifactId>             <version>1.10</version>             <executions>                 <execution>                     <id>timestamp-property</id>                     <goals>                         <goal>timestamp-property</goal>                     </goals>                     <configuration>                         <name>build.time</name>                         <pattern>MM/dd/yyyy hh:mm aa</pattern>                         <locale>en_US</locale>                         <timeZone>America/Detroit</timeZone>                     </configuration>                 </execution>             </executions>         </plugin> 

Then you can utilize the ${build.time} property instead of ${maven.build.timestamp} where you need a timestamp of the build in your preferred timezone.

like image 172
alexanderific Avatar answered Oct 17 '22 03:10

alexanderific