如何让Maven在maven.build.timestamp中显示本地时区? [英] How to have Maven show local timezone in maven.build.timestamp?

查看:3756
本文介绍了如何让Maven在maven.build.timestamp中显示本地时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Maven 3.2.2 +中, maven.build.timestamp 已重新定义,以UTC显示时间,按 MNG-5452

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

有没有办法指明我想要的我当地时区的时区信息而不是UTC时区?我简要地浏览了maven来源,但是无论如何都没有看到我想要TZ是本地TZ而不是基于UTC。

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.

推荐答案

如前所述,在当前版本的Maven中(至少版本为3.3。+), maven.build.timestamp 属性不允许进行时区覆盖。

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.

但是,如果你可以为你的目的使用不同的属性名称, build-helper-maven-plugin 允许您为各种目的配置自定义时间戳。以下是在构建期间配置EST中当前时间戳的示例。

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>

然后你可以利用 $ {build.time} property而不是 $ {maven.build.timestamp} 您需要在首选时区内构建时间戳。

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.

这篇关于如何让Maven在maven.build.timestamp中显示本地时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆