【记录】解决maven 打包spring boot 项目生成的jar包少8小时

问题描述:用maven打包spring boot项目时候,因为想生成的jar包格式为:XXX-yyyyMMdd-HHmmss.jar,方便环境发版

但是,生成的时候每次都少8小时。

解决方式:(我用的第三种方式解决)

1 使用maven自带的属性

设置时间戳格式:在pom.xml文件中加入以下配置

<properties>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>

在打包plugin中引用该属性

<finalName>
  ${project.artifactId}-${project.version}_${maven.build.timestamp}
</finalName>

Maven自带时间戳使用${maven.build.timestamp},但是时区是UTC。 
如果要使用GMT+8,就需要插件提供支持,以下两个插件可以实现。

2 使用buildnubmer-maven-plugin

复制代码
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
        <timestampFormat>yyyyMMdd</timestampFormat>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>create-timestamp</goal>
            </goals>
        </execution>
    </executions>
    <inherited>false</inherited>
</plugin>
复制代码

默认属性是timestamp,在打包plugin中引用该属性

<finalName>
    ${project.artifactId}-${project.version}_${timestamp}
</finalName>

3 使用build-helper-maven-plugin

复制代码
<build>
    <finalName>ProjectName-${current.time}</finalName>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <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>
复制代码

参考地址:https://www.cnblogs.com/winner-0715/p/8398422.html

原文地址:https://www.cnblogs.com/wbl001/p/12327519.html