如何使用Spring Boot Maven插件以ISO格式显示构建时间?
我想在我的执行器信息端点中以ISO 8601格式显示构建时间('Yyyy-MM-DD'HH:MM:SSZ')。构建信息由Spring-Boot-Maven-Plugin生成。
这是一个Spring Boot项目,但我们已经手工配置了很多东西,因为该项目不是Spring Boot Parent Child Project,我们必须使用其他父母。所以也许我错过了一些东西。
我的执行器端点localhost:9090/certuator/info
包含以下构建信息:
"build:{
"artifact":"application",
"name":"application",
"time":1657089305.677000000,
"version":"0.1.0-SNAPSHOT",
"group":"my.group"
}
在我的application.yml
我使用以下配置:
management:
server:
port: 9090
endpoints:
web:
exposure:
include: health,info
info:
build:
enabled: true
java:
enabled: true
git:
enabled: true
在我的pom.xml中
我使用spring-boot-maven-plugin
以下方式:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.3</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
使用此配置,插件将生成一个Build-Info.properties
基于Maven项目。该文件将由执行器使用,这很好。 插件的文档告诉构建信息时间属性以下内容:
outputTimestamp时间戳,可再现的输出存档条目, 格式为ISO 8601(Yyyy-mm-dd'hh:mm:ssxxx)或int 自时代以来代表几秒钟。
更新: 我已经尝试设置Maven属性,但没有帮助我:
<properties>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties>
这很好,但是如何配置使用ISO格式而不是此时代?
I would like to display the build time in ISO 8601 format ('yyyy-MM-dd'T'HH:mm:ssZ') in my actuator info endpoint. The build info is generated by the spring-boot-maven-plugin.
It is a spring boot project but we have configure a lot of things by hand because the project does not a spring boot parent child project, we have to use a different parent. So maybe I miss out something.
My actuator endpoint on localhost:9090/actuator/info
contains the following build info:
"build:{
"artifact":"application",
"name":"application",
"time":1657089305.677000000,
"version":"0.1.0-SNAPSHOT",
"group":"my.group"
}
In my application.yml
I use the following configuration:
management:
server:
port: 9090
endpoints:
web:
exposure:
include: health,info
info:
build:
enabled: true
java:
enabled: true
git:
enabled: true
In my pom.xml
I use the spring-boot-maven-plugin
in the following way:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.3</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
With this configuration, the plugin will generate a build-info.properties
file based on the Maven project. This file will be used by the actuator which is fine. The plugin's documentation tells about the build info time property the following:
outputTimestamp Timestamp for reproducible output archive entries,
either formatted as ISO 8601 (yyyy-MM-dd’T’HH:mm:ssXXX) or an int
representing seconds since the epoch.
Update:
I have tried out setting maven property but it does not helped me:
<properties>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties>
It is fine but how should I configure it to use the ISO format instead of this epoch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要以自定义的方式进行下面的步骤:
将其添加到您的
pom.xml
中:然后通过:
You can follow below steps if you want to do it in a custom way:
Add this into your
pom.xml
:and then reference it via: