论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
朋友圈
看朋友圈动态,了解ToB世界。
ToB门户
了解全球最新的ToB事件
博客
Blog
排行榜
Ranklist
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
导读
Guide
相册
Album
记录
Doing
搜索
本版
文章
帖子
ToB圈子
用户
免费入驻
产品入驻
解决方案入驻
公司入驻
案例入驻
登录
·
注册
只需一步,快速开始
账号登录
立即注册
找回密码
用户名
Email
自动登录
找回密码
密码
登录
立即注册
首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
圈子
SAAS
ToB企服应用市场:ToB评测及商务社交产业平台
»
论坛
›
软件与程序人生
›
后端开发
›
.Net
›
使用Gitee或GitHub托管Maven仓库JAR包的便捷方法 ...
使用Gitee或GitHub托管Maven仓库JAR包的便捷方法
风雨同行
金牌会员
|
2023-7-1 15:48:31
|
显示全部楼层
|
阅读模式
楼主
主题
873
|
帖子
873
|
积分
2619
原文地址:
https://ntopic.cn/p/2023062201/
我开源的JAR包的Gitee和GitHub托管的Maven仓库:
Gitee托管仓库:
https://gitee.com/obullxl/maven-repository
GitHub托管仓库:
https://github.com/obullxl/maven-repository
背景说明
在上一篇博客中,我们介绍了
开源通用高性能分布式id序列组件
(
https://ntopic.cn/p/2023062101/
)的设计思路,并把源代码托管在了Gitee(
https://gitee.com/obullxl/sequence-jdbc
)和GitHub(
https://github.com/obullxl/sequence-jdbc
)。
我们希望能让更多人便捷的使用本组件,那么把JAR包放到到Maven官方的中心仓库(
https://mvnrepository.com
)当然是最好的选择。
然而要把JAR包上传到Maven官方中心仓库,步骤比较繁琐,包括注册、申请、发布配置等一系列操作。其实我们的本意只是想把自己的开源项目打包让大家方便使用,能否有更快捷的方式呢?当然是有的,我们可以使用Gitee或者GitHub作为Maven托管仓库,把我们的组件JAR包存储到托管仓库中。
Gitee/GitHub仓库设置
由于Gitee和GitHub原理完全一致,下面截图说明以Gitee为主(GitHub是我们的主仓库,Gitee只是同步GitHub仓库,但这不妨碍我们的配置)。
建议在Gitee中单独申请一个仓库,专门用于存放JAR包,比如我的仓库叫
maven-repository
:
https://gitee.com/obullxl/maven-repository
同时,便于后续多个组件的JAR包能共用一个托管仓库,JAR包统一放到仓库的repository目录中:
特别注意:仓库请请设置为
开源
,否则其他人使用Maven托管仓库可能无法访问,从而无法下载组件JAR包:
打包发布JAR包到仓库
Gitee托管仓库设置好之后,开始设置我们打包并发布JAR包了。为便于后面设置打包命令,我们把托管Maven仓库的目录maven-repository和id序列组件仓库的目录sequence-jdbc放在同一个父目录中:
OXL-MacBook:CodeSpace obullxl$ ll
drwxr-xr-x 7 obullxl staff 224 6 24 10:30 maven-repository
drwxr-xr-x 13 obullxl staff 416 6 24 17:42 sequence-jdbc
复制代码
组件pom.xml打包配置
完整的配置可直接参考分布式id序列的设置:
https://gitee.com/obullxl/sequence-jdbc/blob/master/pom.xml
pom.xml文件,一定需要定义groupId/artifactId/version这Maven依赖坐标三要素:
<groupId>cn.ntopic</groupId>
<artifactId>sequence-jdbc</artifactId>
<version>1.0.2</version>
<packaging>jar</packaging>
复制代码
pom.xml文件,配置build节点,指定JAR打包、Deploy发布的配置(发布到Maven仓库的目录:../maven-repository/repository),即以下配置的
altDeploymentRepository
内容:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
</execution>
</executions>
<configuration>
<name>BuildTime</name>
<pattern>yyyy-MM-dd HH:mm:ss.SSS</pattern>
<timeZone>GMT+8</timeZone>
<regex/>
<source/>
<value/>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>generate-release</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo file="${project.basedir}/target/classes/NTopic.Release" message="Version=${project.version}${line.separator}BuildTime=${BuildTime}" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.basedir}/../maven-repository/repository</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
复制代码
打包并上传到仓库
打包并发布到本地目录命令:
mvn clean
mvn deploy -Dmaven.test.skip=true
复制代码
上传到远程仓库命令:
cd ./../maven-repository
git add --all
git commit -m 'Deploy sequence-jdbc JAR: https://github.com/obullxl/sequence-jdbc'
git push origin master
复制代码
完整的打包命令,请参考分布式id序列源仓库代码:
https://gitee.com/obullxl/sequence-jdbc/blob/master/deploy.sh
:
#!/bin/bash# 本地打包mvn clean && mvn deploy -Dmaven.test.skip=true# 上传仓库cd ./../maven-repository
git add --all
git commit -m 'Deploy sequence-jdbc JAR: https://github.com/obullxl/sequence-jdbc'
git push origin master# 返回项目cd ../sequence-jdbc# Gitee刷新:人工刷新仓库,从GitHub同步过来open -a '/Applications/Microsoft Edge.app' https://gitee.com/obullxl/maven-repository
复制代码
多个版本
完整的Maven托管仓库内容:
其他项目使用JAR包方法
和Maven官方的中心仓库相比,Gitee托管仓库没有本质区别,只需要在pom.xml中配置Gitee的托管仓库即可,让Maven知道从哪儿去下载JAR包。
pom.xml中增加仓库
pom.xml中增加Gitee托管仓库地址:
<repositories>
<repository>
<id>Gitee-obullxl</id>
<url>https://gitee.com/obullxl/maven-repository/raw/master/repository</url>
</repository>
</repositories>
复制代码
或者增加GitHub托管仓库地址:
<repositories>
<repository>
<id>GitHub-obullxl</id>
<url>https://raw.githubusercontent.com/obullxl/maven-repository/master/repository</url>
</repository>
</repositories>
复制代码
Maven配置依赖
和其他JAR包一样,pom.xml中增加依赖坐标:
<dependency>
<groupId>cn.ntopic</groupId>
<artifactId>sequence-jdbc</artifactId>
<version>1.0.2</version>
</dependency>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
本帖子中包含更多资源
您需要
登录
才可以下载或查看,没有账号?
立即注册
x
回复
使用道具
举报
0 个回复
倒序浏览
返回列表
快速回复
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
or
立即注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
发新帖
回复
风雨同行
金牌会员
这个人很懒什么都没写!
楼主热帖
深入Python网络编程:从基础到实践 ...
MySQL锁(乐观锁、悲观锁、多粒度锁) ...
中职网络安全技能大赛SSH弱口令渗透测 ...
阿里云体验有奖:如何将 PolarDB-X 与 ...
HTML+CSS+JS——动漫风二次元论坛(2页) ...
损失函数-pytorch
让 Flutter 在鸿蒙系统上跑起来 ...
超融合和传统 “VMware + FC SAN& ...
互联网技术大佬独立博客推荐 ...
四、MySQL之数据查询语言(二) ...
标签云
存储
挺好的
服务器
浏览过的版块
前端开发
快速回复
返回顶部
返回列表