多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 一、概述 GitHub Packages 是一种包管理服务,可让你轻松地在源代码旁边发布公共包或专用包; ## 二、发布jar包到Maven仓库 包发布到Maven中之后,只需要通过Maven的POM文件即可完成依赖的引入,无需再使用本地库了,非常方便; ### **安装和配置Maven** 这里基于独立安装,非常简单,参考[开发工具/Maven/安装配置](../Maven/%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE.md); ### **创建token** 在Settings>Developer settings>Personal access tokens里创建一个发布包的token,这个tokens应当能够访问repo的基本信息、读写、删除packages; ![](https://img.kancloud.cn/f9/20/f92041d077f0b47bf13c4a3a6d4439df_1920x942.png) ![](https://img.kancloud.cn/f4/32/f4326c9dd53aaf05c2d1838e6a18b52a_1920x942.png) ![](https://img.kancloud.cn/a9/b3/a9b3cf0e1230b4504c173dcdc2927f9e_1920x942.png) 在Settings>Developer settings>Personal access tokens里创建一个安装包的token,这个tokens应当能够访问repo的基本信息、读; ![](https://img.kancloud.cn/db/3a/db3ab3014c33922fa24184354a1295e4_1920x942.png) ![](https://img.kancloud.cn/11/2e/112e1d3d4b65d821a7c0500bcb4d402c_1920x942.png) ``` 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 ``` ### **配置setting.xml** 可以直接用下面的配置内容覆盖掉setting.xml: ``` <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <activeProfiles> <activeProfile>github</activeProfile> </activeProfiles> <profiles> <profile> <id>github</id> <repositories> <repository> <id>central</id> <url>https://repo1.maven.org/maven2</url> </repository> <repository> <id>github</id> <url>https://maven.pkg.github.com/4170804/raymaven</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <servers> <server> <id>github</id> <username>4170804</username> <password>${token}</password> </server> </servers> </settings> ``` >[danger] > 需要替代: ${token}: 上面创建token环节产生的token字符串,如果当前是发布环境,则需要配置发布环境读写token,如果只是使用,则只需要配置只读的token; ### **配置工程POM** 需要发布包的工程POM文件中,加入 ``` <distributionManagement>  <repository>    <id>github</id>    <name>raymaven</name> <url>https://maven.pkg.github.com/4170804/raymaven</url> </repository> </distributionManagement> ``` ### **执行命令发布** 进入工程根目录,执行命令: ``` cd D:\eclipseray\workspace\rayframework mvn clean mvn deploy -f pom.release.xml -e ``` ![](https://img.kancloud.cn/13/bb/13bb0eaff05059e99b119cabd34f3ca2_1239x647.png) 效果: ![](https://img.kancloud.cn/fa/18/fa180bb9a49551224281a28545103d91_1920x942.png) ![](https://img.kancloud.cn/41/33/4133bf656ff8acc86532dad4f7190f1c_1920x942.png) ![](https://img.kancloud.cn/0f/bf/0fbff298670357b4b5d8cbd1977457c0_1920x942.png) >[danger] > 1、打包的时候,用命令行,关掉eclipse,建议打包的过程,全程不要开eclipse; > 2、如果发布的时候,报证书错误,加入命令行看看:`-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true` ### **包设置为公共** 首次发布包时,默认可见性是私有的,只有您才能看到包。 您可以通过更改访问设置来修改私有或公共容器映像的访问权限; 公共包可以匿名访问,无需身份验证。 包一旦被设为公共,便无法再次将其设为私有。 在 GitHub 上,导航到用户帐户的主页面Your Profile; 在个人资料页面的右上角,单击Packages,选择指定的包; ![](https://img.kancloud.cn/e7/cf/e7cf28750cb8fe426e4d604979a4a27f_1920x942.png) 进入设置页面的Danger Zone,更改包的可见性; ![](https://img.kancloud.cn/9e/a8/9ea8cbb65e61d28aeef7e9105637ce07_1920x942.png) 即可; ### **工程中引用** **配置文件:** 需要在eclipse中,配置Maven的全局设置,设定一个设置文件; ![](https://img.kancloud.cn/37/80/3780e0e42422410275131245ab2e7be6_669x594.png) 配置文件中的内容,可以直接复制下面的文本,完全覆盖即可; ``` <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <activeProfiles> <activeProfile>github</activeProfile> </activeProfiles> <profiles> <profile> <id>github</id> <repositories> <repository> <id>central</id> <url>https://repo1.maven.org/maven2</url> </repository> <repository> <id>github</id> <url>https://maven.pkg.github.com/4170804/raymaven</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <servers> <server> <id>github</id> <username>4170804</username> <password>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</password> </server> </servers> </settings> ``` >[danger] token使用只读的`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` > **工程的POM** 就可以如同公有仓库里面的介质一样,引入依赖即可; ``` <dependencies> <dependency> <groupId>org.ray</groupId> <artifactId>rayframework</artifactId> <version>3.0.1</version> </dependency> </dependencies> ``` 下载到本地库效果: ![](https://img.kancloud.cn/64/29/6429920704f9bb31b5d553813fb450cf_1663x574.png) ## 三、前置条件 为了简化发布库包,把待发布的库包的所有本地依赖包都打入了库包,方便开发者只需要引入一个包即可; 因此,发布库包前,需要把各依赖库全部安装到本地,方可,后续更新,只需更新本地包文件,即可自动更新本地依赖包了; 安装本地包的方法参考:[本地包安装](../Maven/%E6%9C%AC%E5%9C%B0%E5%8C%85%E5%AE%89%E8%A3%85.md) 需要安装的包包括: ``` <!-- uniframework core libs start --> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.core</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.engine</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.integrate</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.internet</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.iot</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.open.core</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.ray.core</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.sysadmin</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.taglib</artifactId> <version>${uniframework.version}</version> </dependency> <dependency> <groupId>org.wbase</groupId> <artifactId>org.wbase.framework.oauth</artifactId> <version>${uniframework.version}</version> </dependency> <!-- uniframework core libs end --> ```