Maven部署在github中的动作不断失败,但在本地运行良好

时间:2020-08-26 14:12:16

标签: maven deployment github-actions

嘿,我一直在尝试使我的github操作在构建和测试更改后部署github包,但是无论我尝试什么,我都会收到以下错误:

[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ topfind-common ---
[INFO] Uploading to github: https://maven.pkg.github.com/topfind/topfindscraper/com/topfind/topfind-common/1.121/topfind-common-1.121.jar
[INFO] Uploading to github: https://maven.pkg.github.com/topfind/topfindscraper/com/topfind/topfind-common/1.121/topfind-common-1.121.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.077 s
[INFO] Finished at: 2020-08-26T14:01:59Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project topfind-common: Failed to deploy artifacts: Could not find artifact com.topfind:topfind-common:jar:1.121 in github (https://maven.pkg.github.com/topfind/topfindscraper) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project topfind-common: Failed to deploy artifacts: Could not find artifact com.topfind:topfind-common:jar:1.121 in github

测试顺利通过,并且工作流文件中包含以下内容:

name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 13
      uses: actions/setup-java@v1
      with:
        java-version: 13
    - name: Get user
      run: echo 'The username is' ${{ github.actor }}
    - name: Build with Maven
      env:
        USERNAME: ${{ github.actor }}
        PASSWORD: ${{ secrets.GITHUB_TOKEN }}
      run: mvn -B -e deploy --file pom.xml --settings settings.xml
    - uses: actions/delete-package-versions@v1
      with:
        package-name: 'com.topfind.topfind-scraper'

我的pom文件具有一个指向存储库的distributionManagement。当我在本地进行mvn部署时,一切正常,并且不需要任何其他操作。有人知道我在做什么错或我想念什么吗?

1 个答案:

答案 0 :(得分:1)

无法看到您的pom文件,我认为该设置需要一些细微的调整。根据您的声明,您的本地版本运行正常,那么我的想法是查看您的管道设置。

代替传递密码,只需传递令牌即可。有关如何设置发布工作流的确切示例,请参见此处 https://docs.github.com/en/actions/language-and-framework-guides/publishing-java-packages-with-maven

分发管理器应具有以下内容

  <distributionManagement>
    <repository>
      <id>github</id>
      <name>GitHub Packages</name>
      <url>https://maven.pkg.github.com/topfind/topfindscraper</url>
    </repository>
  </distributionManagement>

您的工作流程步骤应如下

  - uses: actions/checkout@v2
  - uses: actions/setup-java@v1
    with:
      java-version: 13
  - name: Publish package
    run: mvn -B deploy
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

注意:确保将github令牌作为对软件包的读/写访问权限,以确保允许部署

更新1

注释中的每个请求,这是创建发布令牌的设置

https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token

如果令牌是私人仓库,则令牌也必须具有访问仓库的权限。除此以外。您只需要下面的权限,这取决于您是否希望令牌在处理github软件包时允许读取,写入或删除。

https://docs.github.com/en/packages/publishing-and-managing-packages/about-github-packages

enter image description here