【问题标题】:How to see what Maven is sending to a server during deploy?如何在部署期间查看 Maven 向服务器发送的内容?
【发布时间】:2020-04-12 07:26:19
【问题描述】:

我正在尝试使用 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 传输或可以记录幕后发生的事情?

【问题讨论】:

    标签: maven github-actions github-package-registry


    【解决方案1】:

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

    只需添加秘密:

    ACTIONS_RUNNER_DEBUG
    

    并设置为真

    看到类似的答案here

    【讨论】:

      【解决方案2】:

      如果其他人在这里寻找 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>
      

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

      【讨论】:

      • settings.xml 是在您的用户部署的机器上的所有项目之间共享的,那么它怎么会有一个特定于特定项目的包的 url?
      • 在文件中使用您的个人用户名是没有意义的,该文件将被所有团队成员签入并重复使用。
      • @Sherms 也许不是,但事实仍然是它对我有用。您是否认为软件总是以合理的方式运行?
      • @Jason - 不,但 Github 显然不希望用户作为一个团队一起工作,将给定的项目专门绑定到他们自己的私人 github 帐户。我最终能够在每条路径中使用组织的名称,因此它实际上按预期/记录的方式工作。
      • @Jason - 在此感谢您的建议。您是否知道 Azure DevOps 存储库中是否也存在类似问题?我面临着类似的问题,但设置文件的结构不同,即。不使用配置文件。 link
      【解决方案3】:

      以下解决方案适用于我:

      1. 为包创建一个存储库,例如maven-packages
      2. settings.xml 中的&lt;servers&gt; 下添加&lt;server&gt;&lt;/server&gt; 设置:(根据下面使用的ID 执行此操作)
          <server>
              <id>github</id>
              <username>YOUR GITHUB USERNAME</username>
              <password>A GITHUB TOKEN YOU CREATE FOR PUBLISHING PACKAGES</password>
          </server>
      
      1. 不要&lt;activeProfiles&gt;&lt;profile&gt;&lt;repositories&gt;添加到settings.xml只添加&lt;server&gt;元素),因为这对于发布和我将它们添加到消费项目的maven.xml,因此无需重复。
      2. 将存储库添加到distributionManagement in 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>
      

      注意:在settings.xml&lt;servers&gt; 部分中,为id 定义一个&lt;server&gt;,用于repositoriesdistributionManagement,例如github-snapshot, github-release, github 在上面的例子中。

      【讨论】:

        【解决方案4】:

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

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

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

        【讨论】:

          【解决方案5】:

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

          否则它会这样做

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-04-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-07-07
            • 1970-01-01
            • 2021-10-31
            相关资源
            最近更新 更多