【问题标题】:Nexus Repository Issue while uploading artifact using maven command使用 maven 命令上传工件时出现 Nexus 存储库问题
【发布时间】:2011-08-19 11:30:10
【问题描述】:

正如你上面提到的,我已经更新了 pom

<distributionManagement>

     <repository>
         <id>deployment</id>
         <name>deployment</name>
         <url>http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases</url>
     </repository>

     <snapshotRepository>
         <id>snapshots</id>
         <name>Internal Snapshots</name>
         <url>http://localhost:8080/nexus-webapp-1.9.2/content/repositories/snapshots</url>
     </snapshotRepository>

</distributionManagement>

并将settings.xml 更改为类似的内容

        <server>
            <id>deployment</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>

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

但是当我使用mvn deploy maven 命令进行部署时,我遇到了这样的异常:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project Test: Failed to deploy artifacts: Could not transfer ar
tifact Test:Test:jar:0.0.1 from deployment (http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases): Failed to transfer file: http://localhost:8080/nexus-
webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1/Test-0.0.1.jar. Return code is: 401 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project Test: F
ailed to deploy artifacts: Could not transfer artifact Test:Test:jar:0.0.1 from deployment (http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases): Faile
d to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1/Test-0.0.1.jar. Return code is: 401
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:203)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not transfer artifact Test:Test:jar:0.0.1 from deployment (http://localhost:8
080/nexus-webapp-1.9.2/content/repositories/releases): Failed to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1/Tes
t-0.0.1.jar. Return code is: 401
        at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:189)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
        ... 19 more
Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact Test:Test:jar:0.0.1 from deployment (ht
tp://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases): Failed to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Tes
t/Test/0.0.1/Test-0.0.1.jar. Return code is: 401
        at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:140)
        at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:156)
        ... 21 more
Caused by: org.sonatype.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact Test:Test:jar:0.0.1 from deployment (http://localho
st:8080/nexus-webapp-1.9.2/content/repositories/releases): Failed to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1
/Test-0.0.1.jar. **Return code is: 401**
        at org.sonatype.aether.impl.internal.DefaultDeployer.deploy(DefaultDeployer.java:267)
        at org.sonatype.aether.impl.internal.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:334)
        at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:136)
        ... 22 more
Caused by: org.sonatype.aether.transfer.ArtifactTransferException: Could not transfer artifact Test:Test:jar:0.0.1 from deployment (http://localhost:8080/nexus-webapp-1.9
.2/content/repositories/releases): Failed to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1/Test-0.0.1.jar. Return
code is: 401
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:858)
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:849)
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$PutTask.flush(WagonRepositoryConnector.java:773)
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.put(WagonRepositoryConnector.java:385)
        at org.sonatype.aether.impl.internal.DefaultDeployer.deploy(DefaultDeployer.java:241)
        ... 24 more
**Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://localhost:8080/nexus-webapp-1.9.2/content/repositories/releases/Test/Test/0.0.1
/Test-0.0.1.jar. Return code is: 401**
        at org.apache.maven.wagon.providers.http.LightweightHttpWagon.finishPutTransfer(LightweightHttpWagon.java:205)
        at org.apache.maven.wagon.AbstractWagon.putTransfer(AbstractWagon.java:413)
        at org.apache.maven.wagon.AbstractWagon.transfer(AbstractWagon.java:392)
        at org.apache.maven.wagon.AbstractWagon.putTransfer(AbstractWagon.java:365)
        at org.apache.maven.wagon.StreamWagon.put(StreamWagon.java:163)
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:734)
        at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.put(WagonRepositoryConnector.java:384)
        ... 25 more
[ERROR]
[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

部署用户 ID 和密码是否没有权限使用 maven deploy 在 nexus 中上传工件? 我使用的是 Nexus 1.9.2 Nexus Professional 是否只有上传权限?请指导我。

【问题讨论】:

    标签: maven nexus


    【解决方案1】:

    另外,请确保那里没有同名和版本的工件:) 如果您要部署到发布的 Nexus 存储库,则无法覆盖现有文件。

    【讨论】:

    • 当文件已经存在时,如何防止maven将发布文件上传到Nexus?
    • 我不确定你是否可以 - 但如果你尝试,Nexus 不会让你这样做。
    • 好的,谢谢。我在上传 nexus 版本后通过制作新的 SNAPSHOT 版本解决了这个问题。
    【解决方案2】:

    错误代码 401 表示您无权上传文件。检查用户并首先通过登录,然后检查权限。另一个问题是“部署”经常被禁用。

    【讨论】:

    • 我看到类似的问题,但我得到 400。返回码是:400,ReasonPhrase:错误请求。在 org.apache.maven.artifact.deployer.DefaultArtifactDeployer
    • @Nirmal 400 建议格式错误的请求。建议您发布一个新问题,详细说明您正在尝试做什么
    【解决方案3】:

    您确定您的 Nexus 网址正确吗?本地主机可能是一个糟糕的选择,通常 Nexus 使用上下文关系。

    【讨论】:

      【解决方案4】:

      如果您在机器上本地运行 Hudson,我遇到了同样的问题,由于 windows,它在用户目录中使用他自己的文件结构的 maven settings.xml。我总是在我的 maven 目录中修改 settings.xml。当我将修改后的 xml 复制到 hudson 文件夹时。它起作用了。您可以在此处找到 Hudson settings.xml:

      C:\Users\Username\.hudson\maven\slavebundle\bundled-maven\conf

      如果您想检查这是否是您的问题的解决方案,那么您通过 maven 进行的本地构建可以工作,但任何 Hudson 工作都失败并出现错误 401。我还尝试更改 nexus 用户设置(创建新用户,更改密码设置)由于不同的帖子提出了建议,但这不是我的解决方案。

      【讨论】:

        【解决方案5】:

        您必须加密密码:

        mvn --encrypt-password deployment123
        
        {JipXtsVVaqAHauN0TGDIRWwOmjCdJ3+tdNl7T/nY7hQ=}
        
        
        <username>deployment</username>
        <password>{JipXtsVVaqAHauN0TGDIRWwOmjCdJ3+tdNl7T/nY7hQ=}</password>
        

        【讨论】:

          【解决方案6】:

          我通过将 Maven 从 3.0.5 升级到 3.3.3 版本解决了这个 401 问题。

          我发现这个链接What to do when Nexus returns '401'谈论mvn版本更新。

          • 使用最新版本的 Maven,因为有一个关于 401 的已知问题: MNG-4469

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-05-20
            • 2012-10-20
            • 1970-01-01
            • 2017-05-19
            • 2017-06-16
            • 2021-12-23
            相关资源
            最近更新 更多