首页 > 科技 > 一款小巧实用的git-commit-id-plugin maven插件推荐

一款小巧实用的git-commit-id-plugin maven插件推荐

原创不易,请多多支持!对Java技术感兴趣的童鞋请关注我,后续技术分享更精彩。

背景

后台上线应用是否启动成功,我们可以用healthcheck请求检查。但上线的代码是否生效,我们该如何确认呢?有人可能会说查看应用日志。是的,这是一种方法,却不是一种好的方式。这种方式需保证:每次上线的代码都要打印不同的日志,以示差异。而且查日志过程很繁琐。这里推荐一款git-commit-id-plugin maven插件,很好的解决了该场景问题。

实现思路

git-commit-id-plugin以maven插件方式,集成到项目pom文件中。在项目打包时,通过git指令,获取当前打包项目分支git元数据,并保存这些信息到打包target目录下的git.properties文件中。再配合spring-boot-starter-actuator。应用启动完成,通过http://{domain}/actuator/info接口即可查看最新代码git信息,从而校验新版本是否上线成功。

集成

添加maven插件

pom.xml文件中添加以下插件信息



pl.project13.maven
git-commit-id-plugin
3.0.1


get-the-git-infos

revision

initialize



true
${project.build.outputDirectory}/git.properties


^git.commit.*$
^git.build.*$
^git.branch$
^git.tags$

full

添加spring-boot-starter-actuator依赖


org.springframework.boot
spring-boot-starter-actuator

springboot yml配置添加以下属性

#spring actuator setting
#http://{domain}/actuator/info
management:
info: # 打开info actuator/info请求访问权限
defaults:
enabled: true
git: # https://github.com/git-commit-id/maven-git-commit-id-plugin
mode: full

maven项目打包后,target生成git.properties文件,文件记录git元数据信息如下。

验证

启动项目,浏览器访问http://{ip:port}/actuator/info查看版本信息。

小结

本文通过以下步骤,介绍了git-commit-id-plugin插件从了解到使用的过程。简单集成,立马见效。程序之美无过如此。

  • git-commit-id-plugin maven插件解决的问题场景。
  • git-commit-id-plugin的实现思路。
  • 项目集成示例。

本文来自投稿,不代表本人立场,如若转载,请注明出处:http://www.souzhinan.com/kj/215989.html