github在被大微软收购之后,推出了很多非常不错的功能,这一次把很多仓库管理合并到一起了,包括了nuget,npm,maven,docker等等,今天我们把java代码推到github的maven仓库吧!
申请一个github token
建立一个仓库,起名为maven_repo
配置你的.m2/settings.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/bfyxzls/maven_repo</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>[email protected]</username>
<password>刚才生成的token在这里就不泄漏了</password>
</server>
</servers>
</settings>
在项目pom.xml里指定它,发布者和使用者都需要配置
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/bfyxzls/maven_repo</url>
</repository>
</distributionManagement>
发布你的包到github packages
mvn deploy
你最终发布的包在这里
参考文章
- https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry
- https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package
- https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
作者:仓储大叔,张占岭,