Try   HackMD

Apache Maven for use with GitHub Packages

tags: GitHub Packages Maven

{home_url}/.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>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/{OWNER}/{PREPOSITORY}</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>{USERNAME}</username>
      <password>{TOKEN}</password>
    </server>
  </servers>
</settings>

GitHub Packages does not support SNAPSHOT versions of Apache Maven. Make sure you disable SNAPHOT in your ~/.m2/settings.xml file

如何取得TOKEN

操作流程
需要開啟的權限

  • repo:設定私有存儲庫
    • repo:status:訪問提交狀態
    • repo_deployment:訪問部署狀態
    • public_repo:訪問公共存儲庫
    • repo:invite:訪問存儲庫邀請
  • write:packages:上傳 packages 到 github package
  • read:packages:下載 packages 到 github package
  • delete:packages:刪除 github package

pom.xml

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/{OWNER}/{PREPOSITORY}</url>
   </repository>
</distributionManagement>

部署:

mvn deploy

參考資料

https://stackoverflow.com/questions/58438367/how-to-access-maven-dependecy-from-github-package-registry-beta

https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages