Maven:无法部署工件,拒绝访问

时间:2012-10-04 17:57:08

标签: maven nexus

我有一个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]

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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

输出结果为:

output when mvn deploy succeed

在设置中配置的所有<repository>都与我们在项目pom distributionManagement中使用的不同。如果我把它放在pom中的设置中,就会导致同样的错误forbidden。当我使用用户名和密码aaAA登录nexus服务器时,我找到了正确的网址,我发现有aaaa_snapshort。所以我认为PUT操作的权限实际上更加详细。

答案 2 :(得分: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>