4

我正在尝试使用 Github 的新 Actions CI 服务器将包部署到 Github 的新包功能。进展不顺利。

我认为一切都设置正确,但我收到此错误:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
(default-deploy) on project myproject: Failed to deploy artifacts: Could not 
find artifact com.mycompany:myproject:pom:1.5 in github 
(https://maven.pkg.github.com/mycompany/mycompany_repository) -> [Help 1]

这似乎是在成功上传同一个 pom之后发生的:

Uploading to github: https://maven.pkg.github.com/mycompany/mycompany_repository
/com/mycompany/myproject/1.5/myproject-1.5.pom
Progress (1): myproject-1.5.pom (4.1/6.1 kB)
Progress (1): myproject-1.5.pom (6.1 kB)

因此,在我看来,它正在成功上传 pom,但几秒钟后却无法下载相同的 pom。

我正在使用调试开关运行部署:mvn -X -e deploy,但我看不到 Maven 发送到服务器的确切 http 命令。

我该如何调试?是否有一些 Maven/Aether 传输或可以记录幕后发生的事情的东西?

4

5 回答 5

4

万一其他人在这里寻找解决 OP 问题发布到 github 的解决方案,我遇到了类似的问题,发现 settings.xml 和 pom.xml 中所需的 URL 不一致。在您的 settings.xml 中,repo URL 需要采用https://maven.pkg.github.com/myuser/com/mycompany/mypackage的形式,而在项目的 pom 文件中,它需要采用https的形式://maven.pkg.github.com/myuser/mypackage。因此,例如, ~/.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 Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/myuser/com/mycompany/mypackage</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>myuser</username>
      <password>mypersonalaccesstoken</password>
    </server>
  </servers>
</settings>

而项目根目录中的 pom.xml 文件需要如下所示:

<project>
  ...
  <groupId>org.mycompany</groupId>
  <artifactId>mypackage</artifactId>
  <version>1.0.0</version>
  ...
  <distributionManagement>
    <repository>
      <id>github</id>
      <name>GitHub Apache Maven Packages</name>
      <url>https://maven.pkg.github.com/myuser/mypackage</url>
    </repository>
  </distributionManagement>
  ...
</project>

除了这个次要(但至关重要)的细节之外,我的步骤与此处概述的步骤相同。这允许我将我的 Maven 包发布到 github 包注册表。

于 2020-02-21T06:28:54.603 回答
1

您可以debug logging在工作流中启用。

只需添加秘密:

ACTIONS_RUNNER_DEBUG

并设置为真

在此处查看类似的答案

于 2019-12-20T03:12:18.613 回答
0

生成个人访问令牌时,确保令牌的范围是 repo:* 范围以及更明显的 write:packages 和 read:packages 范围(不要禁用 repo 范围)

否则它就是这样做的

于 2021-01-25T20:46:20.417 回答
0

以下解决方案对我有用:

  1. 为包创建一个存储库,例如maven-packages
  2. 在in下添加<server></server>设置:(根据下面使用的 id 执行此操作)<servers>settings.xml
    <server>
        <id>github</id>
        <username>YOUR GITHUB USERNAME</username>
        <password>A GITHUB TOKEN YOU CREATE FOR PUBLISHING PACKAGES</password>
    </server>
  1. 不要添加, or to (仅添加元素),因为这对于发布来说是多余的,我将它们添加到消费项目中,因此无需重复。<activeProfiles><profile><repositories>settings.xml<server>maven.xml
  2. 将存储库/ies 添加到distributionManagementin 中pom.xml,如下所示:
    <distributionManagement>
        <snapshotRepository>
            <id>github-snapshot</id>
            <name>GitHub snapshot</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
        <repository>
            <id>github-release</id>
            <name>GitHub release</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>false</uniqueVersion>
        </repository>
    </distributionManagement>

OWNER您的项目所在/项目所在的 GitHub 帐户在哪里,并且maven-packages是您要将项目发布到的存储库。

这允许使用专用存储库来列出包,而不是将每个项目的包发布到不同的(它自己的)存储库,从而更容易地从您的 GitHub 帐户使用多个包,因为您只需要为这些包配置一个存储库:

    <repositories>
        <repository>
            <id>github</id>
            <name>GitHub</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
        </repository>
    </repositories>

注意:在上面的示例中,在<servers>settings.xml定义的部分中,例如,中使用的<server>per 。idrepositoriesdistributionManagementgithub-snapshotgithub-releasegithub

于 2020-02-25T16:17:22.763 回答
0

我只花了 3 个小时调试为什么页面上的指南对我不起作用。如果您遵循此处发布的指南1

OWNER 是你的 github 用户名,而 REPOSITORY 是 - 你猜对了,repo 名称。

请记住在 OWNER 和 REPOSITORY 中都使用小写字母。

于 2020-08-28T14:32:09.760 回答