当前位置:   article > 正文

Maven-008-Nexus 私服部署发布报错 Failed to deploy artifacts: Failed to transfer file: ... Return code is: 4X_maven failed to transfer file

maven failed to transfer file

我在部署构件至 maven nexus 私服时,有时会出现 Failed to deploy artifacts: Failed to transfer file: … Return code is: 4XX, ReasonPhrase: … 类似这样的错误,那么这些错误是怎么产生,又如何解决呢?我在此将自己在部署过程中遇到的错误整理汇总一下,供大家参阅,希望对大家有所帮助。

一、错误的请求。Return code is: 400, ReasonPhrase: Bad Request.
  在这里插入图片描述
 具体错误信息如下所示:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.135 s
[INFO] Finished at: 2016-02-18T10:23:58+08:00
[INFO] Final Memory: 19M/174M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project xeger: 
        Failed to deploy artifacts: Could not transfer artifact nl.flotsam:xeger:jar:1.0.2 from/to nexus-releases 
        (http://localhost:8081/nexus/content/repositories/releases/): 
        Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/nl/flotsam/xeger/1.0.2/xeger-1.0.2.jar. 
        Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

400错误的含义是“错误的请求”,在这里的原因是往往是没有部署到nexus的仓库中。产生原因有如下两种:

1、部署仓库错误:

前面的博文有讲过 Nexus 私服有三种仓库类型:Hosted、Proxy和Virtual,另外还有一个 group (仓库组)用于对多个仓库进行组合。部署的时候只能部署到 Hosted 类型的宿主仓库中,如果是其他类型就会出现这个 400 错误。若是出现这个错误,只需修改 POM 文件中的部署仓库到对应的宿主仓库即可解决此问题。

2、宿主仓库不允许重复部署:
  默认情况下重复部署构件到 Releases 仓库中也会出现 400 错误,原因是 Nexus 私服中 Releases 仓库默认的 Deployment Policy 是 “Disable Redeploy”,所以当你重复部署构件至 Releases 宿主仓库时就会出现这个 400 错误。出现这个问题,只需要将宿主仓库的 Deployment Policy 改为 “” 即可解决,解决方法如下所示:

在这里插入图片描述
 二、未认证或认证不通过。Return code is: 401, ReasonPhrase: Unauthorized.
在这里插入图片描述

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.215 s
[INFO] Finished at: 2016-02-18T10:50:56+08:00
[INFO] Final Memory: 19M/175M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project xeger: 
        Failed to deploy artifacts: Could not transfer artifact nl.flotsam:xeger:jar:1.0.2 from/to nexus-releases 
        (http://localhost:8081/nexus/content/repositories/releases/): Failed to transfer file: 
        http://localhost:8081/nexus/content/repositories/releases/nl/flotsam/xeger/1.0.2/xeger-1.0.2.jar. 
        Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

出现这种错误,原因如下所示:

1、是未配置 Nexus 私服用户信息,或配置的账号、密码错误,均会出现 401 的错误,解决方法就是修改 maven settings.xml 配置文件,添加如下信息即可解决问题。

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    ...
    <servers>
        <!-- Nexus 构件部署用户信息 -->
        <server>
            <id>nexus-releases</id>
            <username>fanfengping</username>
            <password>密码</password>
        </server>

        <server>
            <id>nexus-snapshots</id>
            <username>fanfengping</username>
            <password>密码</password>
        </server>
        
    </servers>
    ...
</settings>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

2、是 maven 项目工程 POM 文件中配置的 Nexus 私服宿主仓库的 project.distributionManagement.[repository|snapshotRepository].id 在 maven settings.xml 中配置的宿主仓库 settings.servers.server.id 不存在,统一二者的 ID 后,即可解决此问题。

三、连接失败。Connection refused: connect. 或 Return code is: 405

出现这种错误,肯定是 POM 文件中配置的 url 错误,认真检查一下 url 是否正确,然后订正一下,重新部署即可。

四、缺失私服仓库连接配置。Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

具体提示信息如下所示:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.969 s
[INFO] Finished at: 2016-02-18T10:47:22+08:00
[INFO] Final Memory: 18M/177M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project xeger: 
        Deployment failed: repository element was not specified in the POM inside distributionManagement element 
        or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

此问题是因 POM 文件遗漏了 Nexus 私服连接配置导致的,在 POM 文件中添加 distributionManagement 节点或者在命令行执行时添加 -DaltDeploymentRepository=id::layout::url 参数即可解决。POM 文件中添加 distributionManagement 如下所示:

<project>
    ...
    
    <developers>
        ...
    </developers>
    
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Releases Repository Pro</name>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>

        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshots Repository Pro</name>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    
    
    <dependencies>
        ...
    </dependencies>
    
    <build>
        ...
    </build>
</project>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

五:如果返回Return code is: 400, ReasonPhrase: Bad Request
还有可能是因为pom文件中version格式不规范,比如1.0是不规范的,1.0-SNAPSHOT才是规范的。

转载自:https://www.cnblogs.com/fengpingfan/p/5197608.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/837160
推荐阅读
相关标签
  

闽ICP备14008679号