Error Code 400 when trying to (maven) deploy to github packages using github actions

▼魔方 西西 提交于 2020-01-16 16:26:30

问题


I am struggling with the (seemingly) simple task of deploying a maven project to github packages using a github actions workflow. First of all, here's the error I am getting in the maven deploy phase:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project [project name]: Failed to retrieve remote metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml from/to github (https://maven.pkg.github.com/[username]/[repository]): Failed to transfer file https://maven.pkg.github.com/[username]/[repository]/[groupId as path]/[artifactId]/1.0-SNAPSHOT/maven-metadata.xml with status code 400 -> [Help 1]

(Info: I replaced unneccessary and/or private concrete information with general terms in [brackets])

Most likely, the actual maven-metadata.xml file is not the problem because I have already seen warnings like "could not upload checksum" with status 400 before. I guess that maven-metadata.xml is just the first file it fails on, but probably I am completely wrong with this assumption, please tell me if so.

Probably the most important file is the workflow yaml file:

name: Deploy SNAPSHOT (develop)

on:
  push:
    branches:
      - develop

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Maven Deploy
        env:
          GITHUB_USERNAME: x-access-token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: mvn --settings settings.xml -B -e -Dmaven.wagon.http.pool=false clean deploy

Also quite important: the maven settings.xml file:

<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-packages</activeProfile>
    </activeProfiles>

    <profiles>
        <profile>
            <id>github-packages</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>github</id>
                    <name>GitHub [username] Apache Maven Packages</name>
                    <url>https://maven.pkg.github.com/[username]</url>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <servers>
        <server>
            <id>github</id>
            <username>${env.GITHUB_USERNAME}</username>
            <password>${env.GITHUB_TOKEN}</password>
        </server>
    </servers>
</settings>

(Info: same goes for values in brackets as before)

And lastly, the parent pom.xml of my maven project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>[groupId]</groupId>
    <artifactId>[artifactId]</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        [child modules]
    </modules>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.release>11</maven.compiler.release>
    </properties>

    <dependencies>
        [my dependencies]
    </dependencies>

    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub [username] Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/[username]/[repository]</url>
        </repository>
    </distributionManagement>


</project>

Maybe it's also important to say that the GitHub repository belongs entirely to me and therefore I should have all admin rights on it.

Things I've tried:

I have done some research by now and I found that my issue seems to be not uncommon. Although, from all solutions I've found so far, not one has worked.

  1. Official GitHub documentation for setting up workflows

To start of, I used this site as my reference.

  1. This StackOverflow Question

I mostly stuck to all the advice I found in this question and in the answers to it.

  1. This other StackOverflow Question about nexus deploys

The accepted answer of this question provides a checklist. I tried to check that all the bullet points work for me, although I wasn't able to validate everything. I did not find any issue based on this checklist.

  1. This question on the GitHub community forum

The error displayed in this question looks very much like the error I am getting, still the proposed solution did not fix anything for me.

  1. This Answer on a similar GitHub community forum question

This answer suggested using a personal access token instead of the GITHUB_TOKEN. I tried that and it changed nothing.

What I need

Of course I'd be happy if someone can show me what the exact issue of my case is, but it does not need to be that specific. I am trying to set up the most basic pipeline possible and I currently don't want to do more than just deploy a maven snapshot repository to github packages (with github actions). So, if anyone can show me how to do this properly in general, that's also fine. Thanks!


回答1:


I kinda figured it out myself, but the result is very dissatisfying. The main problem here is:

Note: GitHub Packages does not support SNAPSHOT versions of Apache Maven. Make sure you disable SNAPHOT in your ~/.m2/settings.xml file.

(Source)

So, it seems like GitHub Packages does not support the construct of maven snapshot repositories, which are otherwise very practical. My plan was to set up a workflow that deploys a new SNAPSHOT on the package registry when a push to develop happens. Maven snapshot repositories do not require unique version numbers for deploys, which means I could have built a new version for every push, but the actual dependency version stays fixed. Everyone could then easily try out the latest state of my develop branch, simply by including the fixed snapshot version in their pom files.

Now, how to fix my issue:

Because GitHub packages does not support snapshot repositories, you will have to remove the keyword "SNAPSHOT" from the value in the project.version tag in your pom file. Basically you can put every other version description there, but now it is unique. However if you remove all SNAPSHOT keywords, the workflow should properly deploy a package to the GitHub package registry, at least it worked for me.

If anyone knows a way to "hack" around this SNAPSHOT issue, please tell me. Otherwise this is the only working solution I've found so far.



来源:https://stackoverflow.com/questions/59147676/error-code-400-when-trying-to-maven-deploy-to-github-packages-using-github-act

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!