Maven 项目引用 github 包

1、设置github个人令牌

      1) 登录github后,点击个人头像 ——> Settings ——> Developer settings ——> Personal access tokens ——> Generate new token 

      2) 输入token名,选择授权范围(repo全选,admin:repo_hook选read

      保存后token不可见,记得先复制token

      

 

2、配置maven,settings.xml添加以下内容

      1) <activeProfiles>标签对配置生效的profile,填profile的id

      2) <profiles>标签对下配置github的profile

      3) 将 id 为github的 <repository>中"OWNER"修改为自己github账户名(全小写),"REPOSITORY"替换为自己github上的代码仓名

      4) <servers>标签对下配置自己github的个人令牌

      参考文档 :https://docs.github.com/cn/free-pro-team@latest/packages/guides/configuring-apache-maven-for-use-with-github-packages

  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>
          <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>
</settings>

 


posted @ 2021-01-11 16:51  itur  阅读(840)  评论(0)    收藏  举报