如何将 maven 插件上传到 Github 包?

Kiv*_*van 8 java maven-plugin maven maven-deploy-plugin github-package-registry

考虑我有一个 maven 插件项目,我想将它发布到 Github 的公共 maven 存储库,称为“Github Packages”。我已经按照说明完成了所有工作,对于普通项目,一切开箱即用。但是对于带有 Packaging=maven-plugin 的 maven 插件项目,该指令不起作用。

在构建日志中,我看到如下内容:

[警告] 无法从/向 github ( https://maven.pkg.github.com/user-name/repo-name )传输元数据 repo-name/maven-metadata.xml :无法传输文件: https:/ /maven.pkg.github.com/user-name/repo-name/group-id/maven-metadata.xml。返回码是: 422 , ReasonPhrase:Unprocessable Entity。

似乎maven deploy 插件需要在group-id 的根目录下有maven-metadata.xml,但是找不到它,也没有人把它放在那里。如何解决这个问题呢?

我使用 Apache Maven 3.3.9,并使用以下命令:

mvn clean deploy
Run Code Online (Sandbox Code Playgroud)

--Addition: 我正在使用的 pom 文件示例:

<?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>
Run Code Online (Sandbox Code Playgroud)

Kiv*_*van 1

不幸的是我还没有找到我的问题的正确答案,看来目前不可能将 Maven 插件添加到 Github Packages 中。

不过,我找到了一种使用 S3 作为存储库后端的解决方法,因此您不需要像 Nexus 或 JFrog 这样的重量级解决方案。您可以阅读这篇文章这篇文章来了解如何做到这一点。