在本地工作,在 Github 操作上失败:无法传输 Github 托管父 pom,收到错误请求 parent.relativePath 指向错误的本地 POM

works locally, fails on Github Actions: can't transfer Github hosted parent pom, receives Bad Request an parent.relativePath points at wrong local POM

我正在构建一个项目。
这个项目应该使用我的 parent.pom from the Github registry.

它在我的机器上完美运行,即使我从我的 .m2 存储库中删除了父 pom
不幸的是,每次推送后我总是得到一个 error when Github tries to run the tests,因为无法解析 parent-pom。

[ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for io.joergi:basics:0.0.1-SNAPSHOT: Could not 
transfer artifact io.joergi:parent-jdk11-mongo:pom:2.3.0-1.RELEASE from/to github 
(https://maven.pkg.github.com/joergi/parent-jdk11-mongo): Transfer failed for 
https://maven.pkg.github.com/joergi/parent-jdk11-mongo/io/joergi/parent-jdk11-
mongo/2.3.0-1.RELEASE/parent-jdk11-mongo-2.3.0-1.RELEASE.pom 400 Bad Request and 
'parent.relativePath' points at wrong local POM @ line 5, column 10
     @ 

parent-pom 有这样的定义:

<groupId>io.joergi</groupId>
<artifactId>parent-jdk11-mongo</artifactId>
<version>2.3.0-1.RELEASE</version>
<packaging>pom</packaging>
<name>joergi.io parent-jdk11-mongo</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

我的 new project 使用 Github 操作进行自动测试。
它像这样集成父 pom:

<parent>
    <groupId>io.joergi</groupId>
    <artifactId>parent-jdk11-mongo</artifactId>
    <version>2.3.0-1.RELEASE</version>
</parent>

<distributionManagement>
    <repository>
        <id>github</id>
        <name>GitHub joergi Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/joergi/parent-jdk11-mongo</url>
    </repository>
</distributionManagement>

我在新项目中也有一个settings.xml

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>github</id>
          <name>GitHub joergi Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/joergi/parent-jdk11-mongo</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>joergi</username>
      <password>${{ secrets.PACKAGES_READ_ONLY }}</password>
    </server>
  </servers>

秘密就在我的Github秘密里。如果我删除或更改它,我将不再获得授权,所以这有效。

哪位大侠能指点一下,哪里出了问题

所以,在github community user brightran I was able to fix it, see the post for more information的帮助下。

不知何故,settings.xml 中的秘密密码无法使用,这就是为什么我按照建议采用另一种方式。

在 Maven 部署脚本中,我设置了一个环境变量,如您所见:

- name: Publish to GitHub Packages
  run: mvn deploy -s settings.xml
  env:
    MVN_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

并且在 settings.xml 中我读取了变量,如您所见。

<settings . . .>
  . . .
  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>${MVN_AUTH_TOKEN}</password>
    </server>
  </servers>
</settings>

现在可以按预期工作了。