【问题标题】:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy default-deploy on project未能执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy default-deploy on project
【发布时间】:2016-05-09 22:41:14
【问题描述】:

[错误] 无法在项目上执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy)。 无法部署工件:无法传输工件返回代码为:401,ReasonPhrase:未经授权。 -> [帮助 1]


自上次成功构建以来没有进行任何更改。 我仔细检查了 settings.xml(用户名和密码)。还检查了 pom.xml(分发管理)

我从前 2 天开始就在处理这个问题。我浏览了所有论坛,没有任何效果。请帮助我。

【问题讨论】:

  • 您是否尝试使用相同的 XML 设置在本地运行它,而不是通过 Jenkins 运行它?
  • 我正在努力。
  • 一切正常。
  • 但是当我试图在 Jenkins 上运行构建时抛出 401 ERROR
  • 您需要将设置作为配置文件放入Jenkins中,保存后您可以选择在maven步骤中使用它(高级...)您将看到设置选项。

标签: jenkins maven-3 nexus


【解决方案1】:

此错误消息表示您的机器未正确验证 Nexus 机器。从 Maven 发送到 Nexus 的凭据不正确。

收到此消息后,我通常必须查看我的 settings.xml 以验证这部分中的正确凭据。用户名和密码必须是 Nexus 本身设置的正确用户名和密码。

<servers>
    <server>
        <id>nexus-releases</id>
        <username>fillin</username>
        <password>fillin</password>
    </server>
</servers>

我通常使用 Nexus GUI 并尝试使用这些凭据登录以验证它们,但可以配置可以通过 mvn 发布但不能登录 GUI 的凭据。

一个可能的问题是,如果您使用依赖管理来确定在“mvn deploy”目标的情况下部署的位置。有这样一段:

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>releases</name>
        <url>http://myNexus/more/stuff</url>
    </repository>
</distributionManagement>

并且 id 字段必须与 settings.xml 中凭据上的 id 匹配。如果 id 不匹配,您将收到此错误。

另一个可能的问题是,如果你在 pom.xml 中使用 maven-deply-plugin 的执行,你可能有配置属性

<repositoryId>nexus-releases</repositoryId> 

同样,它与 settings.xml 中的 id 不匹配,因此它会因您的错误而失败。

类似地,如果使用“mvn”命令上的命令行选项进行部署,看起来像这样

-DrepositoryId=nexus-releases

与 settings.xml 中的 id 不匹配,同样,它不起作用。

【讨论】:

    【解决方案2】:

    根据我们在 cmets 部分的讨论, 尝试运行这个 pom.xml

    当 mvn 目标应该是:mvn deploy

    您需要的唯一两件事是拥有一个 pom 并传递参数:

    这是您可以使用的 pom.xml:

    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.hp.Maven</groupId>
        <artifactId>Maven-Nexus</artifactId>
        <packaging>pom</packaging>
        <version>1.0.0</version>
    
        <properties>
            <baseNexusURL>${baseNexusURL}</baseNexusURL>
            <targetRepositoryID>${repositoryId}</targetRepositoryID>
            <package.final.name>${project.artifactId}</package.final.name>
        </properties>
    
            <build> 
            <plugins>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                    <executions>
                        <execution>
                            <id>default-deploy</id>
                            <configuration>
                                <skip>true</skip>
                            </configuration>
                        </execution>
                        <execution>
                            <id>deploy-node-modules-artifact</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy-file</goal>
                            </goals>
                            <configuration>
                                <file>${file}</file>
                                <groupId>${groupId}</groupId>
                                <artifactId>${artifactId}</artifactId>
                                <version>${version}</version>
                                <packaging>${packaging}</packaging>
                                <generatePom>true</generatePom>
                                <repositoryId>${targetRepositoryID}</repositoryId>
                                <url>${baseNexusURL}/content/repositories/${targetRepositoryID}</url>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    【讨论】:

    • 嗨@Shachar Hamuzim Rajuan,实际上密码中存在拼写错误。我已修复。我有另一个错误:400 错误请求。
    • 我在 nexus 上有一些旧工件。当我再次尝试重新部署时,它会抛出“ERROR:400,BAD REQUEST”。
    • 尝试更改工件名称/版本,这样您就可以查看您的问题是您无法覆盖现有工件还是无法上传任何类型的工件(甚至是新工件)
    猜你喜欢
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 2013-04-20
    • 1970-01-01
    • 2020-08-16
    • 2014-01-27
    • 2014-12-04
    相关资源
    最近更新 更多