1

我正在尝试将 Maven 构建 JAR 部署到 Github 包注册表。

mvn deploy执行命令时出现异常。

我正在使用一个简单的 Maven 项目,我想创建一个组件 JAR 并存储在 Github 包注册表中。

构建成功我现在想将此工件部署到注册表。

我在~./m2/settings.xml.

在in下添加了一个repository元素。repositoriesprofile

    <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/swastikaa-in</url>
        </repository>
 <servers>
    <server>
      <id>github</id>
      <username>swastikaa</username>
      <password>my personal token from github</password>
    </server>
  </servers>        

另外,我在 Maven 项目中添加了以下内容pom.xml

 <distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/swastikaa-in/math</url>
   </repository>
</distributionManagement>

预期:部署成功,构建工件被部署到 Github 包注册表。

实际:例外情况如下:

Caused by: org.eclipse.aether.transfer.MetadataTransferException:
  Could not transfer metadata com.redjohn.tools:math:0.0.2-SNAPSHOT/maven-metadata.xml
  from/to github (https://maven.pkg.github.com/swastikaa-in/math):
  Failed to transfer file https://maven.pkg.github.com/swastikaa-in/math/com/redjohn/tools/math/0.0.2-SNAPSHOT/maven-metadata.xml
  with status code 400

Caused by: org.apache.maven.wagon.TransferFailedException:
  Failed to transfer file https://maven.pkg.github.com/swastikaa-in/math/com/redjohn/tools/math/0.0.2-SNAPSHOT/maven-metadata.xml
  with status code 400

有人可以帮我解决这个问题。

我已按照以下链接中提供的说明进行操作:

https://help.github.com/en/articles/configuring-apache-maven-for-use-with-github-package-registry

4

2 回答 2

1

在您的settings.xml文件中,<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>您需要使用OWNER替换为您的 githubusernameREPOSITORY替换为您在 github 中的项目存储库的名称。

于 2019-10-26T08:27:43.930 回答
1

我有同样的问题,我发现快照版本不能很好地工作。如果您部署非快照版本,它应该可以工作。

于 2019-10-23T12:25:32.070 回答