maven使用插件打包, 想使用时间戳作为变量, 时间戳有时差, 变量不生效的问题
·
在使用maven的时候, 有时候打包需要加时间日期的后缀.
每次打tag要手动改很麻烦, 还有一种办法就是使用maven的时间戳生成
<properties>
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
</properties>
然后用变量来使用${maven.build.timestamp}
<imageTag>T-${maven.build.timestamp}</imageTag>
但是这样的时间戳有8小时时差
网上基本推荐的都是使用插件, 比如:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<timestampFormat>yyyyMMddHHmm</timestampFormat>
</configuration>
<executions>
<execution>
<goals>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
<inherited>false</inherited>
</plugin>
默认变量是${timestamp}
但是这里有个坑, 如果我们使用maven的plugin插件进行打包需要这个时间戳变量时, 比如我们用docker的打包, 用的是docker插件打包, docker:build
就会报错
The template variable ‘timestamp’ has no value
这时候就需要使用maven命令把两个插件一起执行, 如:
buildnumber:create-timestamp docker:build
这样才能获取到变量
更多推荐
所有评论(0)