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

Hap*_*ppy 8 nexus maven-3 jenkins

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


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

我从过去 2 天开始研究这个问题。我浏览了所有论坛,没有任何效果。请帮助我。

Lee*_*dor 5

此错误消息表示您的机器没有正确地向 Nexus 机器进行身份验证。从 Maven 发送到 Nexus 的凭据不正确。

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

<servers>
    <server>
        <id>nexus-releases</id>
        <username>fillin</username>
        <password>fillin</password>
    </server>
</servers>
Run Code Online (Sandbox Code Playgroud)

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

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

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>releases</name>
        <url>http://myNexus/more/stuff</url>
    </repository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud)

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

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

<repositoryId>nexus-releases</repositoryId> 
Run Code Online (Sandbox Code Playgroud)

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

同样,如果在“mvn”命令上使用命令行选项进行部署,如下所示

-DrepositoryId=nexus-releases
Run Code Online (Sandbox Code Playgroud)

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


Sha*_*uan 1

按照我们在评论部分的讨论,尝试运行这个 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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述