Maven打包自定义时间戳格式

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.mojogroupId>
                <artifactId>build-helper-maven-pluginartifactId>
                <version>1.9.1version>
                <executions>
                    <execution>
                        <id>timestamp-propertyid>
                        <goals>
                            <goal>timestamp-propertygoal>
                        goals>
                    execution>
                executions>
                <configuration>
                    <name>current.timename>
                    <pattern>yyyyMMdd-HHmmsspattern>
                    <timeZone>GMT+8timeZone>
                configuration>
            plugin>
        plugins>
    build>
project>

如上所述,配置好pom.xml后,执行命令中添加:build-helper:timestamp-property,如:

clean build-helper:timestamp-property install

即可打包带有指定格式和时区的时间戳

你可能感兴趣的:(Maven)