8

Consider I have a maven plugin project and I want to publish it to Github's public maven repository called "Github Packages". I've done everything by instruction and for normal projects everything works fine out of the box. But for maven plugin projects with packaging=maven-plugin the instruction doesn't work.

In build log I see something like this:

[WARNING] Could not transfer metadata repo-name/maven-metadata.xml from/to github (https://maven.pkg.github.com/user-name/repo-name): Failed to transfer file: https://maven.pkg.github.com/user-name/repo-name/group-id/maven-metadata.xml. Return code is: 422 , ReasonPhrase:Unprocessable Entity.

It seems the maven deploy plugin needs maven-metadata.xml in the group-id's root, but can't find it and no one puts it there. How to solve this problem?

I use Apache Maven 3.3.9, and use the command:

mvn clean deploy

--Addition: example of pom file I'm using:

<?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>

<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 my_repo Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/my_nick/my_repo</url>
    </repository>
</repositories>

<version>1.0.0</version>
<groupId>x</groupId>
<artifactId>some-plugin</artifactId>
<packaging>maven-plugin</packaging>

<dependencies>
    <dependency>
        <groupId>x</groupId>
        <artifactId>my-dependency</artifactId>
        <version>1.0.0</version>
    </dependency>

    <dependency>
        <groupId>com.github.javaparser</groupId>
        <artifactId>javaparser-core</artifactId>
        <version>3.15.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.6.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>3.6.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.6.0</version>
        </plugin>
    </plugins>
</build>
</project>
Kivan
  • 1,712
  • 1
  • 14
  • 30

4 Answers4

1

Unfortunately I haven't found the right answer to my question, it seems that for now it's impossible to add Maven plugins to Github Packages.

However I found a workaround which uses S3 as a repository backend, so you don't need heavyweight solutions like Nexus or JFrog. You can read this and this on how to do it.

Kivan
  • 1,712
  • 1
  • 14
  • 30
0

If you have already uploaded the artifact to the GitHub Packages then it means you have configured everything right.

I suppose the real reason for the 422 error is that you are trying to upload the same artifact with the same version that already was uploaded. And if it is not a SNAPSHOT version then the repository should deny replacing it so it behaves correctly.

I got the same error when trying to redeploy the already deployed package:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenPluginForGithub: 
Failed to deploy artifacts: Could not transfer artifact ru.dmochalov:SampleMavenPluginForGithub:jar:1.0.3 from/to github (https://maven.pkg.github.com/dmochalov/hello-world): 
Failed to transfer file: https://maven.pkg.github.com/dmochalov/hello-world/ru/dmochalov/SampleMavenPluginForGithub/1.0.3/SampleMavenPluginForGithub-1.0.3.jar. 
Return code is: 422, ReasonPhrase: Unprocessable Entity. -> [Help 1]

How to fix?

Is suppose you have two options:

  1. Increment the version <version>1.0.0</version> of the plugin from 1.0.0 to 1.0.1. Consider using 1.0.1-SNAPSHOT versions if the plugin is unstable and under development. GitHub allows redeploying artifacts with SNAPSHOT versions. So you could always redeploy it when developing.
  2. Delete the package from the repo. You can do it only for packages in a private repository.

422 error vs 401 error

I suppose that there is not accepted specification or standardization for error codes and different repositories behave differently. For example, the Maven Central repository replies with 401 error when attempting to replace the already deployed version. Why GitHub decided to use 422 is a mystery. There is an answer in the community forum but without proper explanation.

PauMAVA
  • 1,163
  • 14
  • 23
Dmitry.M
  • 2,833
  • 1
  • 17
  • 30
  • Hi Dmitry, thx for you message, but I'm sure it's not the case - versions are OK, I control and to update them as needed not to have the problem you mention. As you can see in my message - build breaks on metadata file, not the JAR file, so the problem is different I think. – Kivan May 02 '20 at 15:13
  • As I have written somewhere on the top - the problem as I understand it, is that when you deploy a plugin, maven needs to get/put something in GROUP ID's metadata, not the artifact metadata file, but exactly into group id's root metadata. I don't know why, but it seems so. And no one puts the metadata to group ids root, so when maven deploy plugin tries to read it from group id root folder, it fail with that error, because there Is no such file in github repo – Kivan May 02 '20 at 15:15
  • @Kivan, Indeed, sorry I haven't noticed that. Could you update your question with the version of the maven and full command that you use to deploy it? – Dmitry.M May 02 '20 at 15:25
  • Added info you needed – Kivan May 02 '20 at 15:50
  • I do have the same error. In my case it's not a plugin, it's a maven project. It uploads but returns 422 error. But as it's a multi module pom, it does not go to the next. Is github packages unusable for maven? – Adriano dos Santos Fernandes Jul 06 '20 at 16:01
0

I had the same problem 422 from server: Unprocessable Entity when publishing Maven artifacts from GitHub Actions to GitHub Packages. The reason was that the corresponding tag for the uploaded artifact didn't exist yet.

The error message may be better in this case.

Marcin Stachniuk
  • 716
  • 7
  • 14
-2

Here's the official github link for how to do exactly that. However, since this doesn't seem to be of much help, here's a link to a gradle forum question that should help you with this. Best of luck!

E_net4
  • 27,810
  • 13
  • 101
  • 139
cuchufleto
  • 31
  • 9
  • 1
    I didn't downvote, however, what a person is writing there doesn't work in my case, because as I stated no one puts the metadata into the root of group id. I don't know why, maybe because maven plugin fails or github forbids to put metadata there. Anyway I added example of POM file I'm using. – Kivan Apr 28 '20 at 18:36