首页 > 解决方案 > 如何将 maven 插件上传到 Github 包?

问题描述

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

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

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

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

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

mvn clean deploy

--添加:我正在使用的 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>

标签: javamavenmaven-pluginmaven-deploy-plugingithub-package-registry

解决方案


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

但是我发现了一种使用 S3 作为存储库后端的解决方法,因此您不需要像 Nexus 或 JFrog 这样的重量级解决方案。你可以阅读这个这个关于如何做的。


推荐阅读