Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Github Package 常见问题(Maven)

running_hyk edited this page Dec 6, 2021 · 1 revision

Maven 常见问题

如果 Maven 出现找不到依赖的错误信息,请检查您的 Maven 配置是否正确。

以下步骤可以为您解决依赖问题


第一步(生成自己Token)

Maven 访问 Github Package 需要使用 Github Person Token,因此需要生成属于自己的Token

您的 Token 相当于密码一样重要,请您注意保管

生成Github Person Token

第二步(找到配置文件)

  • 在 Windows 系统找到 Maven 配置文件
    C:/Users/<username>/.m2/settings.xml
  • 在 Linux 系统找到 Maven 配置文件
    ~/.m2/settings.xml
  • 如果没有找到可以自己手动创建文件,但需要注意您当前使用的是 Maven 项目管理

第三步(修改配置文件)

请按照您实际情况填写配置文件,以下配置文件模板

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- 修改本地依赖库缓存位置 -->
  <localRepository>D:/maven/repository</localRepository>

  <!-- 中央仓库镜像加速(中国大陆地区) -->
  <mirrors>
    <mirror>
      <id>central</id>
      <!-- 此处仅允许加速 certral中央依赖库,注意不要填写 通配符 * -->
      <mirrorOf>central</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>


  <!-- 服务器访问鉴权 -->
  <servers>
    <server>
      <!-- 这里的 Id 需要和 repository 对应,否则会出现 403 无法访问 -->
      <id>github_fightingguys_rabbit</id>
      <!-- Github 个人账户用户名 -->
      <username>填入您的Github用户名</username>
      <!-- Github Person Token -->
      <password>填入您的GithubToken</password>
    </server>
  </servers>


  <profiles>
    <profile>
      <id>github</id>
      <activation>
        <!-- 默认启动当前配置 -->
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <!-- 这里的 Id 需要和 server 对应,否则会出现 403 无法访问 -->
          <id>github_fightingguys_rabbit</id>
          <url>https://maven.pkg.github.com/fightingguys/rabbit</url>
          <!-- 允许使用快照依赖 -->
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>

第四步(重新导入依赖)

回到发生问题的地方,查看问题是否解决