首页 > 其他分享 >使用Gitee或GitHub托管Maven仓库JAR包的便捷方法

使用Gitee或GitHub托管Maven仓库JAR包的便捷方法

时间:2023-07-01 14:44:23浏览次数:39  
标签:GitHub repository 仓库 JAR Gitee maven obullxl

原文地址:https://ntopic.cn/p/2023062201/

我开源的JAR包的Gitee和GitHub托管的Maven仓库:

背景说明

在上一篇博客中,我们介绍了开源通用高性能分布式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-repositoryhttps://gitee.com/obullxl/maven-repository

同时,便于后续多个组件的JAR包能共用一个托管仓库,JAR包统一放到仓库的repository目录中:

image

特别注意:仓库请请设置为开源,否则其他人使用Maven托管仓库可能无法访问,从而无法下载组件JAR包:

image

打包发布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>
                            <!--suppress UnresolvedMavenProperty -->
                            <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托管仓库内容:

image

其他项目使用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>

标签:GitHub,repository,仓库,JAR,Gitee,maven,obullxl
From: https://www.cnblogs.com/obullxl/p/NTopic2023062201.html

相关文章

  • github第三登录
    文章目录第三方登录包创建应用编写代码:oauth2协议github的api简单的认证登录通过justAuth就写完了,自己写的第三方登录包自己使用的:justauth码云文档很详细.我就自己写我是怎么弄得,记录自己的操作过程:创建应用进入github用户的setting,填写:然后就会生成ClientID和密码:......
  • .sh 定时启动脚本 启动jar文件
    进入.sh文件目录下,执行sh命令 #检查脚本是否有问题sh-x start.sh启动命令:sh start.shstart停止命令:sh start.shstop查看状态命令:shstart.shstatus重启命令:sh start.shrestart常见错误:1、$‘\r’:未找到命令错误原因:win文件和linux文件不兼容解决方法,用notepad......
  • jar 包调试
    idea本地运行没有问题  打的jar包接口调用报错 Invalidboundstatementjar调试 原文链接: https://www.jb51.net/article/240922.htm问题解决 原文链接:https://blog.csdn.net/weixin_39034563/article/details/124134568问题:一般情况下,可以打成Jar包的项目,它的源......
  • git已经配置公司的git密钥,想再配置一个私人的git密钥关联github,如何设置
    如果你已经配置了公司的Git密钥,但是想在GitHub上使用私人的Git密钥进行身份验证,可以按照以下步骤进行设置:1.在本地计算机上生成一个新的SSH密钥对。你可以使用ssh-keygen命令来生成新的SSH密钥对,文件名起个其他名字,不要和默认的重复,例如:ssh-keygen-trsa-b4096-C"your_......
  • 这份Github标星30K的神仙面试笔记 ,包含了所有Android中高级大厂知识面试题!!!
    作为一个Android程序员,你平时总是陷在业务开发里,每天噼里啪啦忙敲着代码,上到系统开发,下到Bug修改,你感觉自己无所不能。然而偶尔的一次聚会,你听说和自己一起出道的同学早已经年薪50万,而自己却囊中羞涩。于是你也想看看新机会,找个新平台,好好发展。但是面试的时候,当那个笑眯眯的......
  • 使用宝塔webhook快速部署github仓库上的项目
    1、宝塔安装webhook点击添加Hook,输入如下命令。cd/www/wwwroot/project_namegitpull点击查看密钥,可以得到hooks的地址和密钥。2、Github上设置Webhooks填入上面得到的地址和密钥 3、为了git拉取免登录,需要在服务器安装ssh证书ssh-keygen-trsacat~/.ssh/id_r......
  • Gitee通过本地git上传大于10M的文件教程
    Gitee通过网页端默认上传的文件需要小于10M,如上传10M-100M的文件需要通过本地git上传,此时需要使用git指令操作,步骤如下。首先创建一个文件夹,打开后右键使用gitbash功能分别进行简要步骤说明如下1-8,详细可见下图操作说明。1、gitinit初始化;2、gitremote绑定gitee仓库3、git......
  • JDK/bin目录下的不同exe文件的用途(appletviewer、HtmlConverter、jar、java、javac、
    目录---------------------------------------1.javacexe2.appletviewerexe3.jarexe4.javadocexe5.javahexe6.HtmlConverterexe7.orbdexe8.policytoolexe9.rmicexe10.rmidexe11.rmiregistryexe12.serialverexe13.servertoolexe14.rmic15.rmid16.rmiregistry17.serialver18.jarsi......
  • gitee代码管理工具速通
    ......
  • github花了太长时间响应
    一、访问以下链接:GitHub.com-GitHub:Let'sbuildfromhere·GitHub(ipaddress.com)往下滑倒最下面,记住这个IP地址: 二、打开etc文件夹:C:\Windows\System32\drivers\etc将hosts属性的只读取消勾选: 三、用记事本打开hosts文件:在最后一行添加此IP地址:......