6

我有一个 Sonatype Nexus 服务器,我想部署一个快照。

这是我的 settings.xml 文件的片段:

<servers>
  <server>
    <id>test-snapshots</id>
    <username>myname1</username>
    <password>mypasswd1</password>
  </server>
  <server>
    <id>test-releases</id>
    <username>myname2</username>
    <password>mypasswd2</password>
  </server>
</servers>

这是我的 pom.xml 文件的片段:

<distributionManagement>
  <repository>
    <id>test-releases</id>
    <name>Releases</name>
    <url>https://nxs.company.com/content/repositories/test-releases</url>
  </repository>
  <snapshotRepository>
    <id>test-snapshots</id>
    <name>Snapshots</name>
    <url>https://nxs.company.com/content/repositories/test-snapshots</url>
  </snapshotRepository>
</distributionManagement>

做一个mvn deploy(Maven 3.0.3)我得到这个错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy 
(default-deploy) on project MyProject: Failed to deploy artifacts: 
Could not transfer artifact com.company.project:MyProject:jar:1.0.0-20121003.154427-1 
from/to test-snapshots (https://nxs.company.com/content/repositories/test-snapshots): 
Access denied to: https://nxs.company.com/content/repositories/test-snapshots/
com.company.project/MyProject/1.0.0-SNAPSHOT/MyProject-1.0.0-20121003.154427-1.jar
-> [Help 1]

在我的 Nexus 日志文件中,我看到没有收到任何凭据,所以它稍后会用匿名方式尝试它,这当然会失败。那么为什么没有凭据传递给 Nexus?

2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.apache.shiro.session.mgt.DefaultSessionManager - Unable to resolve session ID from SessionKey [org.apache.shiro.web.session.mgt.WebSessionKey@791a17dc].  Returning null to indicate a session could not be found.
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - Attempting to authenticate Subject as Anonymous request...
2012-10-04 17:24:14 DEBUG [1027496148-8353] - org.sonatype.security.ldap.realms.DefaultLdapContextFactory - Initializing LDAP context using URL [ldap://10.100.100.1:3268/DC=company,DC=com] and username [ldap@company.com] with pooling [enabled]
4

3 回答 3

1

对于 Nexus 中的每个存储库,您真的有不同的用户名/密码吗?这将导致 maven http wagon 出现问题,因为 jvm 缓存每个主机的凭据,即使 maven 正确提供了备用凭据,jvm 也不会使用它们。解决方法是改用 webdav wagon,因为它使用 apache http 客户端而不是 jdk urlclient。

于 2012-10-06T17:00:04.910 回答
0

我们的 Nexus 服务器有多个帐户。在 windows user_home/.m2/settings 它有:

    <server>
        <!-- this id should match the id of the repo server in pom.xml -->
        <id>release-nexus</id>
        <username>aa</username>
        <password>AA</password>
    </server>
    <server>
        <!-- this id should match the id of the repo server in pom.xml -->
        <id>snapshots-nexus</id>
        <username>aa</username>
        <password>AA</password>
    </server>

在项目中:

<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>some.groupid</groupId>
  <artifactId>some-demo</artifactId>
  <version>1.0.0</version>
  
  <distributionManagement>
    <repository>
      <id>release-nexus</id>  
      <name>Maven Repository Switchboard</name>  
      <url>http://nexus.foo.net/nexus/content/repositories/aa/</url> 
    </repository>

    <snapshotRepository>
      <id>snapshots-nexus</id>  
      <name>Maven Repository Switchboard</name>  
      <url>http://nexus.foo.net/nexus/content/repositories/aa_snapshot/</url>  
    </snapshotRepository>
  </distributionManagement>
</project>

跑完之后mvn deploy

输出是:

mvn deploy 成功时的输出

在 settings 中配置的所有<repository>s 都与我们在项目 pom 中使用的不同distributionManagement。如果我将设置中的内容放入 pom 中,则会导致相同的错误forbiddenaa当我使用用户名和密码and登录nexus服务器时,我找到了正确的url AA,我发现有一个aaand aa_snapshort。所以我想PUT操作权限实际上是在更详细的层面上。

于 2018-04-24T03:27:19.160 回答
0

你需要'settings'元素作为根,
把它放在你的settings.xml文件中:

<settings>
    <servers>
        <server>
            <id>test-snapshots</id>
            <username>myname1</username>
            <password>mypasswd1</password>
        </server>
        <server>
            <id>test-releases</id>
            <username>myname2</username>
            <password>mypasswd2</password>
        </server>
    </servers>
</settings>
于 2020-05-22T12:56:43.670 回答