我已经在java中建立了依赖关系。 没什么特别的,只是一些实用功能。 我可以在本地部署它,并且使用它没有问题,但我想将它部署到mavencentral。 我使用 GitHub 设置了 POM,但似乎无法将其部署到我的存储库。 我的 settings.xml 文件位于 .m2 目录中,如下所示。
我安装了 GPG,并且还生成了一个用它生成的密钥。
我的最终目标是我想使用正确的签名/哈希等来构建/部署它,以最终部署到中央。
有人能看到我在这里做错了什么吗? 我觉得这是一些小细节,但我真的不确定
操作系统:Mac OSX Maven版本:尝试了3.9.2和3.8.8,结果相同 IDE:VS Code
我运行 men clean 部署,并得到以下信息:
[INFO] --- deploy:2.8.2:deploy (default-deploy) @ MyArtifactName ---
Uploading to github: https://www.github.com/MyUserName/MyRepoName/io/github/MyUserName/MyArtifactName/1.0/MyArtifactName-1.0.jar
Uploading to github: https://www.github.com/MyUserName/MyRepoName/io/github/MyUserName/MyArtifactName/1.0/MyArtifactName-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.692 s
[INFO] Finished at: 2024-09-08T00:10:46-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MyArtifactName: Failed to deploy artifacts: Could not transfer artifact io.github.MyUserName:MyArtifactName:jar:1.0 from/to github (https://www.github.com/MyUserName/MyRepoName): status code: 301, reason phrase: Moved Permanently (301) -> [Help 1]
[ERROR]
我在很多地方进行了搜索,点击 YouTube、谷歌等寻找一些结果。 我真的认为这与 GitHub 身份验证有关,或者可能与我的设置文件中的某些内容有关,但我不确定。
我已经尝试了几种不同的 POM 文件配置,但似乎都不起作用。 再说一遍,如果我本地部署,或者本地安装,那就没问题了。 一切都按预期进行。
我的用户名 我的仓库名称
<settings>
<servers>
<server>
<id>github</id>
<username>MyUserName</username>
<password>GITHUB_CLASSIC_TOKEN_GENERATED</password>
</server>
</servers>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/MyUserName/MyRepoName</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
我的 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>
<groupId>my.namespace.name</groupId>
<artifactId>MyArtifactName</artifactId>
<version>1.0</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Generic Description</description>
<url>http://www.github.com/MyUserName</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>My Name</name>
<email>[email protected]</email>
<organization>My Name</organization>
<organizationUrl>http://www.github.com/MyUserName</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/MyUserName/MyRepoName.git</connection>
<developerConnection>scm:git:ssh://github.com:MyUserName/MyUserName.git</developerConnection>
<url>http://github.com/MyUserName/MyRepoName/tree/main</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://www.github.com/MyUserName/MyRepoName</url>
</snapshotRepository>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://www.github.com/MyUserName/MyRepoName</url>
</repository>
</distributionManagement>
<properties>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- JUnit -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Most of these are auto generated add ons -->
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- additions from SonaType articles -->
<!-- Distribution Management and Authentication -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>github</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- Javadoc and Sources Attachments -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG Signed Components -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
有一些事情看起来不正确。
<url>https://maven.pkg.github.com/MyUserName/MyRepoName</url>
吗?
您添加的 URL 似乎指向 https://www.github.com/...
,这看起来不正确,可能会导致 301 Moved Permanently 错误。distributionManagement
。settings.xml
文件,该文件需要 GitHub Packages 的正确凭据,并且必须使用具有所需范围(读取:包、写入:包、删除:包、存储库)的个人访问令牌 (PAT)。 GITHUB_PAT 必须正确设置为具有正确范围的个人访问令牌。mvn clean deploy -P github,release