如何使用Spring Boot Maven插件以ISO格式显示构建时间?

发布于 2025-02-13 15:13:07 字数 1948 浏览 0 评论 0原文

我想在我的执行器信息端点中以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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星軌x 2025-02-20 15:13:07

如果要以自定义的方式进行下面的步骤:

将其添加到您的pom.xml中:

<properties>
   <build.timestamp>${maven.build.timestamp}</build.timestamp>
   <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
</properties>

然后通过:

info:
   build-timestamp: @build.timestamp@

You can follow below steps if you want to do it in a custom way:

Add this into your pom.xml:

<properties>
   <build.timestamp>${maven.build.timestamp}</build.timestamp>
   <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
</properties>

and then reference it via:

info:
   build-timestamp: @build.timestamp@
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文