当前位置:网站首页>公共Jar包的版本管理
公共Jar包的版本管理
2022-07-30 08:16:00 【AE86Jag】
背景
项目里面有一个公用的jar包,内容是一些通用的处理逻辑,不同的业务组件引入这个jar包,有的使用正式版本,有的使用SNAPSHOT版本(正式版本上传到仓库必需要改版本,SNAPSHOT版本则不用),不管哪种版本,存在的问题就是,jar包的版本其实和代码是关联不上的,如果遇到问题需要看代码时,我们只知道引入的是哪个版本,并不能看对应版本的代码(jar包的逻辑会随着业务不断的修改或者会新增内容),对定位问题可能会有影响。项目是用gradle进行版本管理的,如果是maven的话可以同样利用这个思路看下是否可行。
解决方案
上传版本成功后,在当前的Commit上打一个tag,并push到远程,前提条件是新加的代码必须先commit或者push到远程,为了避免这种情况,在上传jar之前进行一个校验,先push代码才能上传jar包。如果通过DevOps流水线从Git远程拉的话,就不用加前置校验,因为代码已经是最新的了。
tag的名字如果是正式版本就直接用版本名字当做tag名字,如果是SNAPSHOT那么就在后面加个时间戳。
代码
uploadArchives {
repositories {
doFirst {
//写的比较简单粗暴,读者可以考虑其他更优雅的方式
if (artifactoryUser != null && artifactoryUser.length() != 0) {
def status = "git status".execute()
String gitStatus = status.inputStream.text
println gitStatus
if (gitStatus.contains("Changes not staged for commit") || gitStatus.contains("Changes to be committed")
|| gitStatus.contains("Your branch is ahead of")) {
throw new RuntimeException("请先提交代码")
}
}
}
mavenDeployer {
repository(url: "http://central.xx.xxx.cn/artifactory/third-release-local") {
authentication(userName: xxxx, password: xxxxx)
}
snapshotRepository(url: "http://central.xxxx.cn/artifactory/third-snapshot-local") {
authentication(userName: xxxx, password: xxxxx)
}
}
doLast {
println "start tag"
String versionStr = version.toString()
String tagName = versionStr.contains("SNAPSHOT") ? versionStr + "-" + System.currentTimeMillis() : version
("git tag -a " + tagName + " -m \"upload archives auto tag\"").execute()
println "tag local success"
("git push origin " + tagName).execute()
println "tag push success"
}
}
}
效果
可能会遇到上传成功,但是tag没打成功,这种情况我觉得可以忽略,不用再花代价解决这种一致性问题,可以处理完打Tag失败的,再重新上传。
有人会说换个顺序,先打Tag,再上传Jar包,如果上传成功无需做任何处理,如果上传失败,那么再把tag删掉,也有可能删Tag也出异常,如果打Tag代码没问题,出现失败概率还是比较小,即使出现了再重试下。
边栏推荐
- 激活数据潜力 亚马逊云科技重塑云上存储“全家桶”
- 硬件工程师
- The difference between DDR, GDDR, QDR
- Integral Special Notes-Three Formulas for Curve Area Integral
- stugc_paper
- Golang DES 加解密如何实现?
- 剖析SGI STL空间配置器(allocate内存分配函数)
- Why does typescript2-typescript add type support to js
- BaseQuickAdapter方法getBindingAdapterPosition
- 万字详解:C语言三子棋进阶 + N子棋递归动态判断输赢(另附课设大作业参考)
猜你喜欢
[Mini Program Column] Summarize the development specifications of uniapp to develop small programs
The blockbuster IP that has been popular in the world for 25 years, the new work has become a script paradise
SRAM与DRAM的区别
万字详解:C语言三子棋进阶 + N子棋递归动态判断输赢(另附课设大作业参考)
Why does typescript2-typescript add type support to js
Circuit analysis: constant current source circuit composed of op amp and triode
hcip 第14天学习笔记
一个低级错误导致的诡异现象——走近科学能拍三集,(C语言)最简单的数组元素读取,不正确!?
The FPGA based protocol 2: the I2C read and write E squared PROM
编程界的“躲猫猫”比赛 | 每日趣闻
随机推荐
反射技巧让你的性能提升 N 倍
SQL substring_index() usage - MySQL string interception
Integral Special Notes-Three Formulas for Curve Area Integral
SQL window function
英语语法-名词性从句
【WeChat Mini Program】Page Events
怎么在本地电脑上运行dist文件
2022杭电多校第一场
test2
342 · 山谷序列
sql注入数据库原理详解
stugc_paper
一文带你玩转offer-01
iperf3 参数选项详细说明
SRAM与DRAM的区别
【无标题】
【Flask框架①】——Flask介绍
js currying
leetcode-990:等式方程的可满足性
【Flask框架②】——第一个Flask项目