Maven 專案引用 github 包
阿新 • • 發佈:2021-01-11
1、設定github個人令牌
登入github後,點選個人頭像 ——> Settings ——> Developer settings ——>Personal access tokens ——> Generate new token
輸入token名,選擇授權範圍(repo全選,admin:repo_hook選read)
儲存後token不可見,及得先複製token
2、配置maven,settings.xml新增以下內容
<activeProfiles>標籤對配置生效的profile,填profile的id
<profiles>標籤對下配置github的profile
將id 為github的 <repository>中"OWNER"修改為自己github賬戶名(全小寫),"REPOSITORY"替換為自己github上的程式碼倉名
<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>