網站首頁 編程語言 正文
正文
git-commit-id-maven-plugin插件,會根據當前分支的版本號生成一個git.properties文件。
git.properties內容形如下
git.branch=master
git.build.host=xxx
git.build.time=2022-03-01T20\:33\:43+0800
git.build.user.email=aaa@qq.com
git.build.user.name=aaa
git.build.version=1.0-SNAPSHOT
git.closest.tag.commit.count=
git.closest.tag.name=
git.commit.id=6dab4430864e3e4a9fc1ba6f6b93f278100d4e2e
git.commit.id.abbrev=6dab443
git.commit.id.describe=6dab443-dirty
git.commit.id.describe-short=6dab443-dirty
git.commit.message.full=Add README.md
git.commit.message.short=Add README.md
git.commit.time=2022-03-01T16\:24\:48+0800
git.commit.user.email=aa@example
git.commit.user.name=aa
git.dirty=true
git.remote.origin.url=http://hello
git.tags=
git.total.commit.count=1
如何使用
本文以springboot項目為例,springboot項目的parent pom里面已經內嵌git-commit-id-maven-plugin插件管理依賴。如下
<pluginManagement> ?<plugins> ????<plugin> ??????????<groupId>pl.project13.maven</groupId> ??????????<artifactId>git-commit-id-plugin</artifactId> ??????????<executions> ????????????<execution> ??????????????<goals> ????????????????<goal>revision</goal> ??????????????</goals> ????????????</execution> ??????????</executions> ??????????<configuration> ????????????<verbose>true</verbose> ????????????<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat> ????????????<generateGitPropertiesFile>true</generateGitPropertiesFile> ????????????<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename> ??????????</configuration> ????????</plugin> ???</plugins> </pluginManagement>
項目中做如下配置
1、在我們的項目中顯式引入git-commit-id-plugin插件
<build> ????????<plugins> ????????????<plugin> ????????????????<groupId>pl.project13.maven</groupId> ????????????????<artifactId>git-commit-id-plugin</artifactId> ????????????</plugin> ????????</plugins> ?</build>
2、通過和actuator集成,顯示git信息
a、在項目中引入actuator GAV
<dependency> ????????????<groupId>org.springframework.boot</groupId> ????????????<artifactId>spring-boot-starter-actuator</artifactId> ????????</dependency>
b、瀏覽器訪問http://ip : port/actuator/info
如果覺得上面的信息不夠多,我們可以通過自定義端點或者自己寫一個controller把信息展示出來
詳細的信息可以通過org.springframework.boot.info.GitProperties展示
本示例以自定義端點為例。示例如下
@Endpoint(id =?"git")
@Component
public?class?GitEndpoint?{
????@Autowired(required =?false)
????private?GitProperties gitProperties;
????@ReadOperation
????public?Object?info()?throws?IOException?{
????????if(ObjectUtils.isEmpty(gitProperties)){
????????????return?new?HashMap<>();
????????}
????????return?gitProperties;
????}
}
在application.yml中開放自定義端點
management: ??endpoints: ????web: ??????exposure: ????????include:?'git'
瀏覽器訪問http://ip : port/actuator/git
如果仍然覺得上述的信息還是不夠詳細,那可以通過解析git.properties文件顯示。示例
@Endpoint(id =?"gitDetail")
@Slf4j
@Component
public?class?GitDetailEndPoint?{
????@ReadOperation
????public?Object?detail()?throws?IOException?{
????????Properties props =?null;
????????try?{
????????????props = PropertiesLoaderUtils.loadAllProperties("git.properties");
????????????return?props;
????????}?catch?(IOException e) {
????????????log.error("git.properties not found");
????????}?finally?{
????????}
????????return?new?HashMap<>();
????}
}
在application.yml中開放自定義端點
management: ??endpoints: ????web: ??????exposure: ????????include:?'gitDetail'
瀏覽器訪問http://ip:port/actuator/gitDetail
總結
git-commit-id-maven-plugin在分布式或者微服務項目中,用來驗證項目版本還是挺有用的,推薦大家有機會用一下
demo鏈接
原文鏈接:http://166z.cn/86tP
相關推薦
- 2022-08-04 pandas添加新列的5種常見方法_python
- 2022-08-07 詳解Qt使用QImage類實現圖像基本操作_C 語言
- 2022-07-29 C++超詳細講解數組操作符的重載_C 語言
- 2022-01-27 插入數據庫某個字段之前判斷是否重復
- 2022-05-16 Qt數據庫應用之通用數據庫同步_C 語言
- 2022-10-24 C語言進程程序替換的實現詳解_C 語言
- 2022-12-26 詳解C++11中的lambda匿名函數_C 語言
- 2022-03-16 .net?6項目實現壓縮發布_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支