網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
正文
git-commit-id-maven-plugin插件,會(huì)根據(jù)當(dāng)前分支的版本號(hào)生成一個(gè)git.properties文件。
git.properties內(nèi)容形如下
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項(xiàng)目為例,springboot項(xiàng)目的parent pom里面已經(jīng)內(nèi)嵌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>
項(xiàng)目中做如下配置
1、在我們的項(xiàng)目中顯式引入git-commit-id-plugin插件
<build> ????????<plugins> ????????????<plugin> ????????????????<groupId>pl.project13.maven</groupId> ????????????????<artifactId>git-commit-id-plugin</artifactId> ????????????</plugin> ????????</plugins> ?</build>
2、通過(guò)和actuator集成,顯示git信息
a、在項(xiàng)目中引入actuator GAV
<dependency> ????????????<groupId>org.springframework.boot</groupId> ????????????<artifactId>spring-boot-starter-actuator</artifactId> ????????</dependency>
b、瀏覽器訪問http://ip : port/actuator/info
如果覺得上面的信息不夠多,我們可以通過(guò)自定義端點(diǎn)或者自己寫一個(gè)controller把信息展示出來(lái)
詳細(xì)的信息可以通過(guò)org.springframework.boot.info.GitProperties展示
本示例以自定義端點(diǎn)為例。示例如下
@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中開放自定義端點(diǎn)
management: ??endpoints: ????web: ??????exposure: ????????include:?'git'
瀏覽器訪問http://ip : port/actuator/git
如果仍然覺得上述的信息還是不夠詳細(xì),那可以通過(guò)解析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中開放自定義端點(diǎn)
management: ??endpoints: ????web: ??????exposure: ????????include:?'gitDetail'
瀏覽器訪問http://ip:port/actuator/gitDetail
總結(jié)
git-commit-id-maven-plugin在分布式或者微服務(wù)項(xiàng)目中,用來(lái)驗(yàn)證項(xiàng)目版本還是挺有用的,推薦大家有機(jī)會(huì)用一下
demo鏈接
原文鏈接:http://166z.cn/86tP
相關(guān)推薦
- 2022-02-20 Hive-SQL查詢連續(xù)活躍登錄用戶思路詳解_MsSql
- 2022-12-28 jquery點(diǎn)擊獲取動(dòng)態(tài)數(shù)據(jù)進(jìn)行傳參問題_jquery
- 2022-08-17 R語(yǔ)言繪制corrplot相關(guān)熱圖分析美化示例及詳細(xì)圖解_R語(yǔ)言
- 2022-12-04 C++?Boost.Range與Adapters庫(kù)使用詳解_C 語(yǔ)言
- 2022-08-25 基于Python編寫一個(gè)點(diǎn)名器的示例代碼_python
- 2022-04-18 設(shè)置彈性布局的三列兩側(cè)對(duì)齊,最后一行樣式的處理
- 2023-01-10 Vmware虛擬機(jī)設(shè)置主機(jī)端口映射方式_VMware
- 2022-09-06 C語(yǔ)言超詳細(xì)講解猜數(shù)字游戲的實(shí)現(xiàn)_C 語(yǔ)言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支