我的前置条件:Github 学生认证附赠的 packet
我使用了 personal access token (PAT) 来认证 GitHub Packages / GitHub API
参考(很详细,一步一步来):https://docs.github.com/en/enterprise-server@3.1/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
<servers>
标签中添加一个 <server>
标签
USERNAME
TOKEN
<repositories>
标签中
<repositories>
标签中的 id
的值与 <server>
标签中的 id
的值进行映射,保持一致(即复制 <server>
标签中的 id
的值到 <repositories>
标签中的 id
标签)OWNER
(注意:因为不支持大写字母,所以必须使用小写字母,如果 ID 中包含了大写字母,将其转换为小写字母即可)<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/OWNER/*</url> <!-- 改 OWNER -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>USERNAME</username> <!-- 改 USERNAME -->
<password>TOKEN</password> <!-- 改 TOKEN -->
</server>
</servers>
</settings>
<distributionManagement>
标签OWNER
改成自己的 IDREPOSITORY
改成仓库名<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name> <!-- 改 OWNER -->
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url> <!-- 改 OWNER、REPOSITORY -->
</repository>
</distributionManagement>
使用以下命令发布 package:
$ mvn deploy
例:https://jitpack.io/#tzq0301/common-api-1.0.0/1.0.0
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
将页面中提供的 gav dependency 添加到自己的构建文件中即可
<dependency>
<groupId>com.github.tzq0301</groupId>
<artifactId>common-api-1.0.0</artifactId>
<version>1.0.0</version>
</dependency>
dependencies {
implementation 'com.github.tzq0301:common-api-1.0.0:1.0.0'
}