发布到Maven中央仓库

4

我被添加为Maven项目的开发者,现在需要发布一个版本。 我已经将nexus-staging-maven-plugin添加到pom.xml文件中。

<plugin>
  <groupId>org.sonatype.plugins</groupId>
  <artifactId>nexus-staging-maven-plugin</artifactId>
  <version>1.6.3</version>
  <extensions>true</extensions>
  <configuration>
    <serverId>ossrh</serverId>
    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
    <autoReleaseAfterClose>true</autoReleaseAfterClose>
  </configuration>
</plugin>

我已经在pom.xml中添加了distributionManagement
<distributionManagement>
  <snapshotRepository>
    <id>ossrh</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  </snapshotRepository>
  <repository>
    <id>ossrh</id>
    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  </repository>
</distributionManagement>

我已将我的凭据放置在~/.m2/settings.xml中。

<settings>
  <servers>
    <server>
      <id>ossrh</id>
      <username>divanov-oss.sonatype.org-account</username>
      <password>divanov-oss.sonatype.org-password</password>
    </server>
  </servers>
</settings>

我还尝试创建和使用oss.sonatype.org上的“Access User Token”作为我的凭据。

现在我正在执行将发布部署到Maven中央仓库的操作。

mvn clean deploy

这最终导致了错误:

[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.3:deploy
(injected-nexus-deploy) on project project: Failed to deploy artifacts:
Could not transfer artifact
project:jar:4.4.0-20141228.104011-1 from/to ossrh
(https://oss.sonatype.org/content/repositories/snapshots): Access denied to:
https://oss.sonatype.org/content/repositories/snapshots/project/project/4.4.0-SNAPSHOT/project-4.4.0-20141228.104011-1.jar,
ReasonPhrase: Forbidden. -> [Help 1]

或者

[INFO] Performing remote staging...
[INFO] 
[INFO]  * Remote staging into staging profile ID "329a0bc2b7ce06"
[ERROR] Remote staging finished with a failure: 403 - Forbidden
[ERROR] 
[ERROR] Possible causes of 403 Forbidden:
[ERROR]  * you have no permissions to stage against profile with ID "329a0bc2b7ce06"? Get to Nexus admin...

我如何检查我在Maven项目中发布时的访问权限?


根据您的配置,快照和阶段存储库具有两个相同的ID。我不建议这样做。除此之外,您是否尝试使用给定的凭据登录oss nexus?此外,为什么要使用nexus-staging插件而不是通常的deploy插件? - khmarbaise
我按照Apache Maven文档(http://central.sonatype.org/pages/apache-maven.html)的指导进行操作,其中示例中使用了相同的ID。他们的建议是否有误? - divanov
那么再试一次。你尝试使用给定的凭据登录了吗?成功了吗? - khmarbaise
我可以在https://oss.sonatype.org登录,但是我无法登录我安装和启动的本地Nexus OSS。"用户名、密码不正确或没有权限使用Nexus用户界面。请重试。在尝试进一步请求之前,请先登录。"我不确定是否需要本地Nexus OSS才能发布到远程存储库。 - divanov
我可以在oss.sonatype.org登录。但是我无法使用相同的凭据登录到我的本地Nexus OSS。我不确定是否需要本地Nexus OSS才能发布到远程存储库。 - divanov
2个回答

4
您的凭证很可能是正确的,如果不正确,您将收到401错误。但您收到了403(禁止)错误。这意味着凭证已被接受,但您没有权限发布构件。最常见的原因是您使用的Maven组ID与分配给您的不同。请在“社区支持-开源项目存储库托管”中提交问题,网址为https://issues.sonatype.org,我们会解决此问题。

我已经在https://issues.sonatype.org上提交了一个错误报告。并且我的权限已经被Maven管理员解决了。感谢他们。然而,我仍然不知道是否这是找到和更改权限的唯一方法? - divanov

-1

您需要使用的凭据不应该是 Sonatype JIRA 的凭据,而应该是 oss.sonatype.org 的凭据。您需要在那里单独注册。

[更新] 问题已更改,因此此答案不再相关。我将保留它,因为这是一个常见的错误。


看着这一切的疯狂,让我建议您使用Bintray。简单得多。 - JBaruch
我不记得有单独注册过,但是我在JIRA和oss.sonatype.org上使用的是同一组凭据。我甚至尝试在oss.sonatype.org上创建并使用了“Access User Token”。 - divanov
问题是:“我如何在我正在尝试发布的Maven项目中检查我的访问权限?”坦率地说,对于这个问题仍然没有确切的答案。 - divanov
嗯,这是Sonatype的事情...所以你应该问他们,没有太多选择。 - JBaruch
凭据目前在JIRA https://issues.sonatype.org/,NXRM服务器https://oss.sonatype.org/和https://s01.oss.sonatype.org/上相同(LDAP)。 - julian-alarcon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接