![](https://img.haomeiwen.com/i1846623/6f61cdc3ceed2ab3.png)
# Steps:
- 生成用于发布、安装和删除 GitHub 包的访问令牌。
- 配置你的
.m2/settings.xml
。 - 设置你需要发布的maven项目。
- deploy。
- 愉快的使用
- say: 🐂🍺
1. 生成TOKEN令牌
- 路径:Settings -> Developer settings -> Person Access Tokens
![](https://img.haomeiwen.com/i1846623/cc5531d2a9ab8f11.png)
![](https://img.haomeiwen.com/i1846623/a68841e5648fdebc.png)
-
设置该Token的名字与授权的权限
image.png
-
生成成功(记得保存好自己的TOKEN哟,如果遗失了也可以重新生成)
image.png
2. 设置你的.m2/settings.xml
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
</servers>
-
USERNAME
替换为你的github账号。 -
TOKEN
替换为第一步生成的访问令牌。 -
OWNER
替换为拥有该仓库的用户或组织帐户的名称 -
REPOSITORY
替换为包含项目的仓库的名称 -
看起来长这样:
image.png
![](https://img.haomeiwen.com/i1846623/e531b114abf79940.png)
3. 设置项目的POM文件
- 设置pom文件
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</distributionManagement>
- 注意
id
需要设置成第二步中设置的server.id
-
OWNER
替换为拥有该仓库的用户或组织帐户的名称 -
REPOSITORY
替换为包含项目的仓库的名称 - 看起来长这样:
![](https://img.haomeiwen.com/i1846623/096926f36c5ea774.png)
4. deploy
-
到目前为止你的github-packages可能还长这样
image.png
但是一炷香之后... -
在项目中执行
mvn deploy -Dmaven.test.skip=true
将项目生成的依赖发布到github
image.png
-
现在看看~满满登登嘚
image.png
- 点进去还可以看到历史版本
![](https://img.haomeiwen.com/i1846623/aa60dd39cdc59698.png)
-
注意:同一个版本号不可重复deploy,否则会失败
image.png
5. 使用
- 使用刚刚发布的依赖坐标
<dependency>
<groupId>com.lazy.starter</groupId>
<artifactId>lazy-cache</artifactId>
<version>1.2.5</version>
</dependency>
- 如果出现无法下载的情况,需要在pom文件中添加仓库信息
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/FutaoSmile/LazyStarter</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
-
Downloading from github
image.png
网友评论