springboot~關(guān)于打包時記錄當(dāng)前git信息
Maven打包發(fā)布版本可能會遇到自己的提交不起作用的情況,排查比較困難,可能需要拉下服務(wù)器上包,反編譯查看是否包含自己的提交記錄。如果使用的是GIT作為SCM,可以使用 git-commit-id-plugin插件
該插件在打包時生產(chǎn)一個git.properties文件,里面記錄本次git提交的信息。

#Generated by Git-Commit-Id-Plugin
git.build.time=2022-07-28 09\:15\:53
git.build.version=1.0.0
git.commit.id=dc8103b5cf9d51d59169e0682e9990456a72f231
git.commit.id.abbrev=dc8103b
git.commit.id.describe=dc8103b-dirty
git.commit.id.describe-short=dc8103b-dirty
git.commit.message.full=update cache log
git.commit.message.short=update cache log
git.commit.time=2022-07-28 08\:58\:43
- 可以在父項目中添加這個插件,這樣子項目也就具有了這個能力
<!--打包jar 與git commit 關(guān)聯(lián)插件-->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>${git.commit.plugin}</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!--因為項目定制了jackson的日期時間序列化/反序列化格式,因此這里要進行配置,不然通過management.info.git.mode=full進行完整git信息監(jiān)控時會存在問題-->
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.(id|message|time).*$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
浙公網(wǎng)安備 33010602011771號