无法执行目标org.apache.maven.plugins:maven-deploy-plugin:2.7:在项目上部署default-deploy

问题描述 投票:1回答:2

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


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

我从最近2天开始研究这个问题。我经历了所有论坛,没有任何作用。请帮助我。

jenkins maven-3 nexus
2个回答
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-deploy-plugin的执行,则可能具有配置属性

<repositoryId>nexus-releases</repositoryId> 

并且它再次与settings.xml中的id不匹配,因此它会因您的错误而失败。

同样,如果在“mvn”命令中使用命令行选项进行部署,则看起来像这样

-DrepositoryId=nexus-releases

与settings.xml中的id不匹配,再次,它将无法正常工作。


0
投票

按照我们在评论部分中的讨论,尝试运行此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>

enter image description here

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