Maven自帶時間戳使用${maven.build.timestamp},但是時區是UTC。
如果要使用GMT+8,就需要插件提供支持,我用的是build-helper-maven-plugin,
官方文檔:
http://www.mojohaus.org/build-helper-maven-plugin/usage.html
但是按照官方文檔配置後,打包時報錯:
The parameters 'name' for goal org.codehaus.mojo:build-helper-maven-plugin:1.9.1:timestamp-property are missing or invalid
最終找到解決辦法是把“configuration”標籤放在“executions”標籤同級,難道是官網搞錯了?
終極代碼:
<project>
......
<build>
<finalName>ProjectName-${current.time}</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
</execution>
</executions>
<configuration>
<name>current.time</name>
<pattern>yyyyMMdd-HHmmss</pattern>
<timeZone>GMT+8</timeZone>
</configuration>
</plugin>
</plugins>
</build>
</project>
如上所述,配置好pom.xml後,執行命令中添加:build-helper:timestamp-property,如:
clean build-helper:timestamp-property install
即可打包帶有指定格式和時區的時間戳