怎么添加github的依赖
时间: 2023-11-03 14:59:28 浏览: 38
要添加 GitHub 仓库作为依赖项,需要在项目的 `pom.xml` 文件中添加以下内容:
```xml
<dependencies>
<dependency>
<groupId>组织ID</groupId>
<artifactId>项目ID</artifactId>
<version>版本号</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>github</id>
<name>GitHub MyProject Apache Maven Packages</name>
<url>https://maven.pkg.github.com/组织ID/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub MyProject Apache Maven Packages</name>
<url>https://maven.pkg.github.com/组织ID/</url>
</repository>
</distributionManagement>
```
其中,`groupId`、`artifactId`、`version` 分别对应 GitHub 仓库的项目 ID、Maven 坐标和版本号。`repositories` 和 `distributionManagement` 部分配置了 GitHub 的 Maven 仓库地址。
需要注意的是,在进行依赖下载时,需要提供 GitHub 的访问凭证。可以在 GitHub 上创建一个 personal access token,然后在 `~/.m2/settings.xml` 文件中添加以下内容:
```xml
<settings>
<servers>
<server>
<id>github</id>
<username>username</username>
<password>personal-access-token</password>
</server>
</servers>
</settings>
```
其中,`id` 对应 `pom.xml` 中的 `<repository>` 中的 `id`,`username` 是 GitHub 用户名,`password` 是 personal access token。这样,就可以通过 Maven 下载 GitHub 仓库的依赖了。