为什么在Maven中出现“ 401未经授权”错误?


115

为什么我在Maven中收到“ 401未经授权”错误?

这是调用时出现的错误mvn deploy(底部是完整日志):

[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]

根据此sonatype支持页面

“如果您收到401,则是因为maven发送的登录凭据错误,或者根本没有凭据。”

下面是我执行的步骤,下面是我的完整目录settings.xmlpom.xml文件,下面是来自mvn deploy和的完整日志mvn deploy -e

任何想法,将不胜感激。我只是和Maven碰壁。


收到401错误时,我遵循了sonatype的清单

清单项目1登录Nexus用户界面,确保您的用户名/密码正确。如果您的计算机上安装了curl,则可以尝试使用以下命令部署工件:

  • 我使用的用户/密码成功登录和退出了sonatype.org网站settings.xml
  • 尝试使用curl以下命令手动部署工件

[C:\]curl -u MY_SONATYPE_DOT_COM_USERNAME:MY_SONATYPE_DOT_COM_PASSWORD https://oss.sonatype.org/content/repositories/snapshots/com/github/aliteralmind/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.224928-1.pom --request PUT --data @pom.xml

但是出现了这个错误:

Warning: Couldn't read data from file "pom.xml", this makes an empty POST.
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

我再次使用该-k选项运行它,这次只有这个:

Couldn't read data from file "pom.xml", this makes an empty POST.

我以前从未使用过curl,因此我对如何处理此信息一无所知。

清单项目2如果没有错误输出,请确保在服务器上正确配置了用户权限。确保删除刚刚创建的存储库。

我不知道“掉线”是什么意思。我相信我的权限已正确安装,因为我收到了来自sonatype的消息:

并且在过去的几天中,我成功将这些物品放到服务器上mvn deploy

项目的设置:

项目设置

清单项目3确保已在其中配置了服务器,settings.xml并且该服务器标识与pom.xml中的分发存储库标识相同。

  • 在中settings.xml,设置/服务器/服务器/ ID等于ossrh
  • 在中pom.xml,distributionManagement / snapshotRepository / id等于ossrh

(完整文件位于底部)

清单项目4确保您的settings.xml在正确的位置(通常是_〜/ .m2 / settings.xml)。您可以通过运行mvn help:effective-settings进行检查。

根据Maven的设置参考,settings.xml必须位于以下两个位置之一:

  • Maven安装: $M2_HOME/conf/settings.xml
  • 用户的安装: ${user.home}/.m2/settings.xml

这是我的设置:

  • settings.xmlC:\applications\programming\apache-maven-3.2.2\conf\settings.xml
  • M2_HOMEC:\applications\programming\apache-maven-3.2.2

输出为mvn help:effective-settings

[C:\applications\utilities\curl]
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:effective-settings (default-cli) @ standalone-pom ---
[INFO]
Effective user-specific configuration settings:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2014-07-18T12:48:19                  -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective Settings for 'jeffy' on 'kermit-the-frog'                    -->
<!--                                                                        -->
<!-- ====================================================================== -->

<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc
hemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">C:\Users\jeffy\.m2\repository</localRepository
>
  <servers xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <server>
      <username>MY_SONATYPE_DOT_COM_USERNAME</username>
      <password>***</password>
      <id>ossrh</id>
    </server>
  </servers>
  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <pluginGroup>org.apache.maven.plugins</pluginGroup>
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
</settings>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.310 s
[INFO] Finished at: 2014-07-18T12:48:19-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------

清单项目5如果服务器使用https,但POM中的URL为http,则可能也会得到401。

我不明白它指的是哪个网址。

清单项目6使用最新版本的Maven,因为存在有关401的已知问题:MNG-4469

我正在使用最新版本:

[C:\]mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:42-04:00)
Maven home: C:\applications\programming\apache-maven-3.2.2
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\applications\programming\jdk_7_51\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

------------------

完整settings.xmlpom.xml文件

(全为记录mvn deploymvn deploy -e下面)

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>
     <server>
       <id>ossrh</id>
       <username>MY_SONATYPE_DOT_COM_USERNAME</username>
       <password>MY_SONATYPE_DOT_COM_PASSWORD</password>
     </server>
   </servers>

   <pluginGroups></pluginGroups>
   <proxies></proxies>
   <mirrors></mirrors>
   <profiles></profiles>
</settings>

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.github.aliteralmind</groupId>
   <artifactId>xbnjava</artifactId>
   <packaging>pom</packaging>
   <version>0.1.2</version>
   <name>XBN-Java</name>
   <url>https://github.com/aliteralmind/xbnjava</url>
   <inceptionYear>2014</inceptionYear>
   <organization>
      <name>Jeff Epstein</name>
   </organization>
   <description>XBN-Java is a collection of generically-useful backend (server side, non-GUI) programming utilities, featuring RegexReplacer and FilteredLineIterator. XBN-Java is the foundation of Codelet (http://codelet.aliteralmind.com).</description>

   <parent>
      <groupId>org.sonatype.oss</groupId>
      <artifactId>oss-parent</artifactId>
      <version>7</version>
   </parent>

   <licenses>
      <license>
         <name>Lesser General Public License (LGPL) version 3.0</name>
         <url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
      </license>
      <license>
         <name>Apache Software License (ASL) version 2.0</name>
         <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      </license>
   </licenses>

   <developers>
      <developer>
         <name>Jeff Epstein</name>
         <email>aliteralmind-github@yahoo.com</email>
         <roles>
            <role>Lead Developer</role>
         </roles>
      </developer>
   </developers>

   <issueManagement>
      <system>GitHub Issue Tracker</system>
      <url>https://github.com/aliteralmind/xbnjava/issues</url>
   </issueManagement>

   <distributionManagement>
      <snapshotRepository>
         <id>ossrh</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      </snapshotRepository>
   </distributionManagement>

   <scm>
      <connection>scm:git:git@github.com:aliteralmind/xbnjava.git</connection>
      <url>scm:git:git@github.com:aliteralmind/xbnjava.git</url>
      <developerConnection>scm:git:git@github.com:aliteralmind/xbnjava.git</developerConnection>
   </scm>

   <properties>
      <java.version>1.7</java.version>
      <jarprefix>R:\jeffy\programming\build\/${project.artifactId}-${project.version}/download/${project.artifactId}-${project.version}</jarprefix>
   </properties>
<!--
  <profiles>
    <profile>
      <id>default-tools.jar</id>
      <activation>
        <property>
          <name>java.vendor</name>
          <value>Sun Microsystems Inc.</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>1.4.2</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
 -->
   <build>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
               <execution>
                  <id>attach-artifacts</id>
                  <phase>package</phase>
                  <goals>
                     <goal>attach-artifact</goal>
                  </goals>
                  <configuration>
                     <artifacts>
                        <artifact>
                           <file>${jarprefix}-all.jar</file>
                           <type>jar</type>
                        </artifact>
                     </artifacts>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

   <profiles>
      <!--
      This profile will sign the JAR file, sources file, and javadocs file using the GPG key on the local machine.
      See: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
      -->
      <profile>
         <id>release-sign-artifacts</id>
         <activation>
            <property>
               <name>release</name>
               <value>true</value>
            </property>
         </activation>
      </profile>
   </profiles>
</project>

------------------

对于全日志mvn deploymvn deploy -e

mvn deploy 输出:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.2\xbnjava-0.1.2.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.2\download\xbnjava-0.1.2-all.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.2\xbnjava-0.1.2.jar
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom
2/6 KB
4/6 KB
6/6 KB

(故障部分:)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.204 s
[INFO] Finished at: 2014-07-18T11:25:17-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. 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

mvn deploy -e 输出:

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.2\xbnjava-0.1.2.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.2\download\xbnjava-0.1.2-all.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.2\xbnjava-0.1.2.jar
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom
2/6 KB
4/6 KB
6/6 KB

(故障部分:)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.492 s
[INFO] Finished at: 2014-07-18T11:25:37-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
   at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
   at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
   at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
   at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
   at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
   at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
   at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
   at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
   at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
   at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
   at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
   at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:193)
   at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
   ... 19 more
Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
   at org.apache.maven.plugin.deploy.AbstractDeployMojo.deploy(AbstractDeployMojo.java:167)
   at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:149)
   ... 21 more
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:337)
   at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:268)
   at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:413)
   at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
   ... 23 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1016)
   at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1004)
   at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:895)
   at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.put(WagonRepositoryConnector.java:522)
   at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:331)
   ... 26 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
   at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:573)
   at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:493)
   at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:474)
   at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:454)
   at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:871)
   ... 28 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

仅供参考:“ MY_USERNAME” /“ PASSWORD”占位符仅在此问题中。我在登录时以及在真实设置文件中使用我的真实用户/密码。
aliteralmind 2014年

1
第3项:服务器ID与存储库ID匹配的必要性是胡说八道,但是不幸的是,这是如何工作的,您的回答很有帮助,谢谢!
索马尔·索马尔斯基

Answers:


51

尝试将Gradle人工制品部署到Nexus Sonatype存储库时,我遇到了类似的错误。如果您提供错误的凭据(密码等),则会收到401未经授权的错误。如果您尝试将某些内容发布到发行版本存储库中并且该版本已存在于存储库中,则还会收到错误消息(并且在我的头上也是401) 因此,您可能会发现通过在命令行中发布它可以正常工作,但是随后在通过脚本执行时它就会失败(因为它第一次不在存储库中存在)。可以使用其他版本号发布,也可以删除服务器上的旧产品并重新发布。

SNAPSHOTS存储库(与releases存储库相对)使您可以覆盖编号相似的版本,但是版本号的末尾应带有“ -SNAPSHOT”。


2
难以置信的。正如您所建议的,似乎0.1.2-SNAPSHOT已经创建的会干扰我的新0.1.2版本。它更改为0.1.0(“早”),或0.1.2a,或0.1.3(“后”),结果在我的错误这一个前处理:
aliteralmind

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project xbnjava: Failed to install artifact com.github.aliteralmind:xbnjava:jar:0.1.3: R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3-all.jar (The system cannot find the path specified) -> [Help 1]。我认为我没有进行任何更改,但是显然-SNAPSHOT从版本中删除它是一件坏事。
aliteralmind 2014年

46
为什么在
世界范围内

2
仔细检查您为您的凭据配置的存储库的ID(在settings.xml或POM中)是否与您要部署到的存储库相匹配。刚刚偶然发现了这一点。
格雷戈尔

我还遇到一个问题,当我尝试发布1.2.0-SNAPSHOT时已经有一个1.3.0发行版...
Marcello de Sales

12

发生此错误的原因之一是未指定或错误指定了repositoryId时。如前所述,它应该与settings.xml中的部分相同。几个提示...使用-e -X选项运行mvn并检查调试输出。它将告诉您它正在使用哪个repositoryId:

[DEBUG]   (f) offline = false
[DEBUG]   (f) packaging = exe
[DEBUG]   (f) pomFile = c:\temp\build-test\pom.xml
[DEBUG]   (f) project = MavenProject: org.apache.maven:standalone-pom:1 @ 
[DEBUG]   (f) repositoryId = remote-repository
[DEBUG]   (f) repositoryLayout = default
[DEBUG]   (f) retryFailedDeploymentCount = 1
[DEBUG]   (f) uniqueVersion = true
[DEBUG]   (f) updateReleaseInfo = false
[DEBUG]   (f) url = https://nexus.url.blah.com/...
[DEBUG]   (f) version = 13.1
[DEBUG] -- end configuration --

在这种情况下,它使用默认值“ remote-repository”,这意味着出了点问题。

显然,我指定了-DrepositoryID(大写的便笺ID)而不是-DrepositoryId。


这为我解决了问题,但我还发现工作区中的其他项目找不到名称唯一的发行版回购(它们会在我们的Central代理中查找工件)。我们正在使用发布插件的2.5.3。因此,在我的settings.xml文档中,我再次使两个存储库ID相同(快照和发行版),但是随后我为同一发行版存储库添加了另一个具有唯一ID的声明(基本上是别名)。这允许需要唯一名称的项目引用它,而使用相同名称的较早项目则可以引用它们。我们的主绒球是指相同的东西。

9

就像aliteralmind所说的那样,只需更改settings.xml即可:

  <server>
      <id>nexus-snapshots</id>
      <username>MY_SONATYPE_DOT_COM_USERNAME</username>
      <password>MY_SONATYPE_DOT_COM_PASSWORD</password>    
 </server>

您可能需要从sonatype dot com获取用户名/密码。


很好。解决了我的问题
Dhiral Pandya

也为我工作!
伊戈尔·伯伯罗汀

我也是!非常感谢。
詹姆斯·泰勒

8

我在settings.xml中输入了未加密的密码。

我用卷发测试了电话

curl -u username:password http://url/artifactory/libs-snapshot-local/com/myproject/api/1.0-SNAPSHOT/api-1.0-20160128.114425-1.jar --request PUT --data target/api-1.0-SNAPSHOT.jar 

我得到了错误:

{
  "errors" : [ {
    "status" : 401,
    "message" : "Artifactory configured to accept only encrypted passwords but received a clear text password."
  } ]
}

单击我的工件概要文件并将其解锁,我检索了加密的密码。


1
提示:许多curl实现需要在URL之前添加选项。在这种情况下,请code curl -u username:password --request PUT --data target/api-1.0-SNAPSHOT.jar http://url/artifactory/libs-snapshot-local/com/myproject/api/1.0-SNAPSHOT/api-1.0-20160128.114425-1.jar改用
TouDick '16

4

也有Nexus的401。尝试了以上所有建议,但都没有成功,我最终发现这是Jenkins设置出现错误。

在失败项目的Jenkins配置中,“构建后”操作中有一节名为“将工件部署到Maven存储库”。此字段的“存储库ID”字段设置为错误的值。它必须与settings.xml中的存储库ID相同,Jenkins才能读取用户和密码字段:

Jenkins项目配置

 <servers>
    <server>
      <id>snapshot-repository</id>  <!-- must match this -->
      <username>deployment</username>
      <password>password</password>
    </server>
  </servers>

3

如@John的回答所述,已经有一个事实0.1.2-SNAPSHOT干扰了我的新非SNAPSHOT版本0.1.2。由于401 Unauthorized错误是模糊的且无济于事的-通常与用户/密码问题相关,因此我无法自行解决这一问题也就不足为奇了。

更改版本0.1.3使我回到我原来的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project xbnjava: Failed to install artifact com.github.aliteralmind:xbnjava:jar:0.1.3: R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3-all.jar (The system cannot find the path specified) -> [Help 1].

一个声纳类型的支持人员还建议我<parent>从POM中删除该块(之所以存在,是因为它位于ez-vcard的块中,这是我开始的目的),然后将其替换<distributionManagement>

<distributionManagement>
  <snapshotRepository>
    <id>ossrh</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  </snapshotRepository>
  <repository>
    <id>ossrh</id>
    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  </repository>
</distributionManagement>
and then make sure that lines up with what's in your settings.xml:
<settings>
  <servers>
    <server>
      <id>ossrh</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
  </servers>
</settings>

完成此操作后,运行mvn deploy实际上是第一次上传我的一个罐子!

输出:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.3\xbnjava-0.1.3.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava\0.1.3\xbnjava-0.1.3.jar
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.pom
2/6 KB
4/6 KB
6/6 KB

Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.pom (6 KB at 4.6 KB/sec)
Downloading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml
310/310 B

Downloaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml (310 B at 1.6 KB/sec)
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml
310/310 B

Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml (310 B at 1.4 KB/sec)
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.jar
2/630 KB
4/630 KB
6/630 KB
8/630 KB
10/630 KB
12/630 KB
14/630 KB
...
618/630 KB
620/630 KB
622/630 KB
624/630 KB
626/630 KB
628/630 KB
630/630 KB

(成功部分:)

Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.jar (630 KB at 474.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.632 s
[INFO] Finished at: 2014-07-18T15:09:25-04:00
[INFO] Final Memory: 6M/19M
[INFO] ------------------------------------------------------------------------

这是完整更新的POM:

<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.github.aliteralmind</groupId>
  <artifactId>xbnjava</artifactId>
  <packaging>pom</packaging>
  <version>0.1.3</version>
  <name>XBN-Java</name>
  <url>https://github.com/aliteralmind/xbnjava</url>
  <inceptionYear>2014</inceptionYear>
  <organization>
     <name>Jeff Epstein</name>
  </organization>
  <description>XBN-Java is a collection of generically-useful backend (server side, non-GUI) programming utilities, featuring RegexReplacer and FilteredLineIterator. XBN-Java is the foundation of Codelet (http://codelet.aliteralmind.com).</description>

  <licenses>
     <license>
        <name>Lesser General Public License (LGPL) version 3.0</name>
        <url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
     </license>
     <license>
        <name>Apache Software License (ASL) version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
     </license>
  </licenses>

  <developers>
     <developer>
        <name>Jeff Epstein</name>
        <email>aliteralmind-github@yahoo.com</email>
        <roles>
           <role>Lead Developer</role>
        </roles>
     </developer>
  </developers>

  <issueManagement>
     <system>GitHub Issue Tracker</system>
     <url>https://github.com/aliteralmind/xbnjava/issues</url>
  </issueManagement>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

  <scm>
     <connection>scm:git:git@github.com:aliteralmind/xbnjava.git</connection>
     <url>scm:git:git@github.com:aliteralmind/xbnjava.git</url>
     <developerConnection>scm:git:git@github.com:aliteralmind/xbnjava.git</developerConnection>
  </scm>

  <properties>
     <java.version>1.7</java.version>
     <jarprefix>R:\jeffy\programming\build\/${project.artifactId}-${project.version}/download/${project.artifactId}-${project.version}</jarprefix>
  </properties>
  <build>
     <plugins>
        <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>build-helper-maven-plugin</artifactId>
           <version>1.8</version>
           <executions>
              <execution>
                 <id>attach-artifacts</id>
                 <phase>package</phase>
                 <goals>
                    <goal>attach-artifact</goal>
                 </goals>
                 <configuration>
                    <artifacts>
                       <artifact>
                          <file>${jarprefix}.jar</file>
                          <type>jar</type>
                       </artifact>
                    </artifacts>
                 </configuration>
              </execution>
           </executions>
        </plugin>
     </plugins>
  </build>

  <profiles>
     <!--
     This profile will sign the JAR file, sources file, and javadocs file using the GPG key on the local machine.
     See: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
     -->
     <profile>
        <id>release-sign-artifacts</id>
        <activation>
           <property>
              <name>release</name>
              <value>true</value>
           </property>
        </activation>
     </profile>
  </profiles>
</project>

那是Maven的一大难题。仅剩627个。


2

有些用户可能误输入了电子邮件地址而不是用户名。当电子邮件地址中的名称与用户名相同时,可能会无意识地发生这种情况。


这使用sonatype nexus 2.12为我解决了问题。我必须将settings.xml中的电子邮件地址更改为一个用户名
spuder

2

这是sonatype nexus团队对401的官方解释-未经授权

我建议您阅读对Artifact部署失败进行故障排除以获取更多信息。

代码401-未经授权

没有与请求一起发送登录凭证,或者发送了无效的登录凭证。在Nexus UI中检查“授权和身份验证”系统供稿有助于缩小范围。如果发送了凭据,则提要中将有一个条目。

如果未发送凭据,则可能是由于pom的distributionManagement部分中的ID与保存登录凭据的settings.xml的server部分中的ID不匹配所致。


2

以我为例,在加密密码后,我忘了settings-security.xml输入〜/ .m2。


1

我们最近才遇到这个问题,发现这与我们使用的Maven版本有关。我们使用的是3.1.0,无法上载到nexus,我们一直获取401,然后恢复为3.0.3,问题消失了。

确认的最简单方法是遍历Maven版本并在项目上运行“ mvn deploy”。

可以在这里找到更多详细信息:https : //issues.apache.org/jira/browse/WAGON-421


1

我正在处理运行的Artifactory版本5.8.4。“设置我”功能将生成settings.xml,如下所示:

<servers>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP56eMPz8L12T5u4J6rWdqWqyhQ"}</password>
      <id>central</id>
    </server>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP56eMPz8L12T5u4J6rWdqWqyhQ"}</password>
      <id>snapshots</id>
    </server>
</servers>

使用mvn deploy -e -X开关后,我注意到凭据不正确。我删除了$ {security.getCurrentUsername()}并将其替换为我的用户名,并删除了$ {security.getEscapedEncryptedPassword()!“”},然后输入对我有用的加密密码:

<servers>
    <server>
      <username>username</username>
      <password>AP56eMPz8L12T5u4J6rWdqWqyhQ</password>
      <id>central</id>
    </server>
    <server>
      <username>username</username>
      <password>AP56eMPz8L12T5u4J6rWdqWqyhQ</password>
      <id>snapshots</id>
    </server>
</servers>

希望这可以帮助!


听起来您在其他地方配置了错误的值,因为它应该使用安全性对象中的值,或者使用默认值。但是很高兴它起作用了!
Rup

1

在Nexus 3.13.0-01版id中,POM distributionManagement/repository部分中的务必与您的maven settings.xml 中的servers/server/id和 匹配mirrors/mirror/id。我只是用nexus v3.10.4(用3.13.0-01)代替了它,所以不需要匹配3.10.4。


1

有类似的问题。必须将maven deploy插件固定到pom.xml中的特定版本:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
     <version>2.8.2</version>
</plugin>

这个版本破坏了我的构建:

[INFO] --- maven-deploy-plugin:3.0.0-M1:deploy (default-cli) @ dbl ---

它确实起到了帮助,如果撤消了许可,则奋斗了几天探索人工制品,然后发现了这一点。
卡西克·普拉萨德

0

我有同样的错误。我尝试并重新检查了所有内容。我是如此专注于堆栈跟踪,以至于在Reactor摘要和堆栈跟踪之前,我没有读过构建的最后几行:

[DEBUG] Using connector AetherRepositoryConnector with priority 3.4028235E38 for http://www:8081/nexus/content/repositories/snapshots/
[INFO] Downloading: http://www:8081/nexus/content/repositories/snapshots/com/wdsuite/com.wdsuite.server.product/1.0.0-SNAPSHOT/maven-metadata.xml
[DEBUG] Could not find metadata com.group:artifact.product:version-SNAPSHOT/maven-metadata.xml in nexus (http://www:8081/nexus/content/repositories/snapshots/)
[DEBUG] Writing tracking file /home/me/.m2/repository/com/group/project/version-SNAPSHOT/resolver-status.properties
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.zip
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:

这是关键:“找不到元数据”。尽管它说这是一个身份验证错误,但实际上它是通过在关系存储库中执行“重建元数据”来解决的。

希望能帮助到你。


我收到相同的“找不到元数据”调试消息,但实际错误是另一个:我使用了错误的用户名。
rwitzel 2015年

0

另外,在更新存储库ID之后,请确保干净运行release:prepare,因为它会从中断处恢复。因此,您可以执行以下操作:

mvn release:prepare -Dresume=false 要么

mvn release:clean release:prepare


0

Windows中有两个setting.xml。

  • %MAVEN_HOME%\conf\
  • %userprofile%\.m2\

如果%userprofile%\.m2\setting.xml生效,maven将无法访问%MAVEN_HOME%\conf\setting.xml


0

这可能是由于版本错误引起的,您可以仔细检查父级lib的版本,以确保它们是正确的并且没有重复,我遇到了同样的问题


0

401使用mvn gpg:sign-and-deploy-file命令时出现错误,原因是其中<MVN_HOME>/conf/settings.xml不包含<server>可以通过https://oss.sonatype.org/#profile;User%20Tokenwhere 获得的标签,该标签<id>-DrepositoryId

要获得<MVN_HOME>运行mvn --version


0

就我而言,我从设置中删除了用于Central的服务器登录凭据。

    <server> 
        <id>central</id>
        <username>admin</username> 
        <password>******</password> 
    </server>

   <mirror>
        <id>central</id>
        <mirrorOf>central</mirrorOf>
        <name>maven-central</name>
        <url>http://www.localhost:8081/repository/maven-central/</url>
   </mirror> 

我不知道为什么要这么做,但是这完全是错误的,因为可以匿名访问中央Maven存储库。查看导致我的错误识别和解决的调试输出。

[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://www.localhost:8081/repository/maven-central/ with username=admin, password=***


-1

尝试部署到Artifactory存储库时遇到了相同的错误,以下内容为我解决了这个问题:

转到工件中的存储库设置,并启用“ Force Maven Authentication ”(强制Maven身份验证)点和401“ Unauthorized”错误。(当然,您最好在 settings.xml文件中以纯文本形式提供凭据,以防止出现问题

我想默认情况下,即使通过在settings.xml文件中提供正确的凭据,它们也不会被使用,并且会出现Unauthorized异常。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.