从 Maven 部署 Nexus 中的工件会出现错误“返回代码是:401”?

问题描述 投票:0回答:5

我在 Nexus 中部署时收到 401 错误。我没有对已安装的 Nexus 进行任何更改。 Nexus 正在

localhost:8080/nexus
上运行,我可以使用默认用户/密码登录。当我运行时
mvn deploy
我收到此错误。

这是我的 POM。

 <groupId>testproject</groupId>
 <artifactId>testproject</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>testproject</name>
 <url>http://maven.apache.org</url>
 <distributionManagement>
  <repository>
      <id>releases</id>
      <url>http://localhost:8080/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
       <id>snapshots</id>
       <url>http://localhost:8080/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>
<dependencies>
 .........
</dependencies>

和 ~/.m2/settings.xml

<servers>
    <server>
        <id>snapshots</id>
        <username>deployment</username>
        <password>deployment123</password>
    </server>
    <server>
        <id>releases</id>
        <username>deployment</username>
        <password>deployment123</password>
    </server>
</servers>

例外:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-           deploy) on project testproject: Failed to deploy artifacts: Could not transfer artifact testproject:testproject:jar:1.0-20131213.150615-1 from/to snapshots (http://localhost:8080/nexus/content/repositories/snapshots): Failed to transfer file: http://localhost:8080/nexus/content/repositories/snapshots/testproject/testproject/1.0-SNAPSHOT/testproject-1.0-20131213.150615-1.jar. 
Return code is: 401 -> [Help 1]

请帮助我。

maven nexus
5个回答
20
投票

现在正在工作。需要编辑

${MVN_HOME}/conf/settings.xml
而不是
/home/{user}/.m2/settings.xml


3
投票

HTTP 401 是“未经授权”的状态代码,这意味着您的

deployment
用户无权将工件上传到 Nexus 中的特定存储库。登录到 Nexus 并为
deployment
用户提供更改该快照存储库所需的角色。


1
投票

我的

<servers>
上缺少
.m2/settings.xml
标签 Gitlab-ci + MAVEN + Jfrog Artifactory:

我的gitlab-ci.yxml

Artifactory_deploy:
  stage: install
  only:
    - desarrollo
  script:
    - echo "Deploying to Artifactory"
    - cd $CLONE_DIR
    - mvn -X deploy

我的.m2/settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <username>${ARTIFACTORY_USER}</username>
      <password>${ARTIFACTORY_PASSWORD}</password>
      <id>central</id>
    </server>
    <server>
      <username>${ARTIFACTORY_USER}</username>
      <password>${ARTIFACTORY_PASSWORD}</password>
      <id>snapshots</id>
    </server>
  </servers>
  <profiles>
    <profile>
    <id>develop</id>
      <properties>
        <artifactory.ip>${ARTIFACTORY_IP}</artifactory.ip>
        <artifactory.port>${ARTIFACTORY_PORT}</artifactory.port>
      </properties>
    <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <username>admin</username>
          <password>THISWASMYENCRYPTEDPASSWORD</password>
          <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <username>admin</username>
          <password>THISWASMYENCRYPTEDPASSWORD</password>
          <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <username>admin</username>
          <password>password</password>
          <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <username>admin</username>
          <password>password</password>
          <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
<activeProfiles>
   <activeProfile>develop</activeProfile>
 </activeProfiles>
</settings>


<servers>
    <server>
        <id>snapshots</id>
        <username>deployment</username>
        <password>deployment123</password>
    </server>
    <server>
        <id>releases</id>
        <username>deployment</username>
        <password>deployment123</password>
    </server>
</servers>

1
投票

用于快照部署的用户需要具有以下权限的角色:

  • nx-存储库-视图-maven2-maven-快照-读取
  • nx-存储库-视图-maven2-maven-快照-编辑
  • nx-存储库-视图-maven2-maven-快照-添加

0
投票

我在尝试部署到本地 Nexus 服务器时出现问题。状态 401 故障是间歇性的,并且并不总是在同一对象上。我的解决方案是将以下内容添加到我的 pom 中:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8</version>
    <configuration>
        <retryFailedDeploymentCount>2</retryFailedDeploymentCount>
    </configuration>
</plugin>

设置 retryFailedDeploymentCount 参数会导致插件重试上传所有文件,并在第二次尝试时成功部署所有内容。

© www.soinside.com 2019 - 2024. All rights reserved.