ftk*_*tkg 10 maven github-actions github-package-registry
我的构建通过直接在元素上使用 User + PAT(个人访问令牌)在本地运行pom.xml
<repository>
:
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://[USER]:[PAT]@maven.pkg.github.com/myaccount/myrepo</url>
</repository>
Run Code Online (Sandbox Code Playgroud)
从github下载:https://[USER]:[PAT]@maven.pkg.github.com/myaccount/myrepo/org/springframework/flex/spring-flex-core/1.6.1.BUILD-SNAPSHOT/maven- metadata.xml(796 B,592 B/s)
我的没有settings.xml
配置。
然而,它在 Github Actions 工作流程上出现了问题:
警告:无法从 github 传输元数据 org.springframework.flex:spring-flex-core:1.6.1.BUILD-SNAPSHOT/maven-metadata.xml (***maven.pkg.github.com/myaccount/myrepo ):https: //maven.pkg.github.com/myaccount/myrepo/org/springframework/flex/spring-flex-core/1.6.1.BUILD-SNAPSHOT/maven-metadata.xml身份验证失败 401 未经授权
无法在 org.springframework.flex:spring-flex-core:jar:1.6.1.BUILD-SNAPSHOT 收集依赖项:无法读取 org.springframework.flex:spring-flex-core:jar:1.6.1 的工件描述符.构建快照
我的工作流程是这样的:
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package --file dev/server/pom.xml
Run Code Online (Sandbox Code Playgroud)
为什么 Github 工作流程会中断?
m.g*_*shi 16
Based on your question I suppose:
GitHub Package
, we call it library
library
package as a dependency in its pom.xml, we call this project as your app
GitHub Actions
in app
repositoryIf your library
is a public package even, currently unfortunately the GitHub dose not support unauthorized access from maven
for public packages. Therefore, you should do as follow:
First of all, you need to generate a PAT access token with package-read access in your profile setting, in developer setting
subsection:
Go to setting section of your app
repository, and in the subsection of Secrets
create two environment secrets called USER_NAME
which the value contains your GitHub username (or username of the owner of library
package); and ACCESS_TOKEN
point to the value of PAT token which created in previous step.
Now, create a maven-settings.xml
in the app
repository, for example you can create it, along side your workflow.yml
file. the file contains:
<?xml version="1.0" encoding="UTF-8"?>
<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>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/owner_username/package_name</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>${env.USER_NAME}</username>
<password>${env.ACCESS_TOKEN}</password>
</server>
</servers>
</settings>
Run Code Online (Sandbox Code Playgroud)
workflow.yaml
file can contain:name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Build with Maven
run: mvn -s $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml -B package --file pom.xml
env:
USER_NAME: ${{ secrets.USER_NAME }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8065 次 |
最近记录: |