Why am I getting a “401 Unauthorized” error in Maven?

前端 未结 21 1641
栀梦
栀梦 2020-11-29 18:06

Why am I getting a \"401 Unauthorized\" error in Maven?

Here\'s the error I\'m getting when calling mvn deploy (full logs at the bottom):

相关标签:
21条回答
  • 2020-11-29 18:12

    just change in settings.xml these as aliteralmind says:

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

    you probably need to get the username / password from sonatype dot com.

    0 讨论(0)
  • 2020-11-29 18:12

    In Nexus version 3.13.0-01, the id in the POM's distributionManagement/repository section MUST match the servers/server/id and mirrors/mirror/id in your maven settings.xml. I just replaced nexus v3.10.4 (with 3.13.0-01) and it wasn't needed to match for 3.10.4.

    0 讨论(0)
  • 2020-11-29 18:13

    It could be caused by wrong version, you can double check the parent's version and lib's version, to make sure they're correct and not duplicated, I've experienced same problem

    0 讨论(0)
  • 2020-11-29 18:15

    Had similar issue. Had to pin the maven deploy plugin to specific version in pom.xml:

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

    This version is what broke my builds:

    [INFO] --- maven-deploy-plugin:3.0.0-M1:deploy (default-cli) @ dbl ---
    
    0 讨论(0)
  • 2020-11-29 18:17

    I've had similar errors when trying to deploy a Gradle artefact to a Nexus Sonatype repository. You will get a 401 Unauthorized error if you supply the wrong credentials (password etc). You also get an error (and off the top of my head is also a 401) if you try to publish something to a releases repository and that version already exists in the repository. So you might find that by publishing from the command line it works, but then when you do it from a script it fails (because it didn't exist in the repository the first time around). Either publish using a different version number, or delete the old artefact on the server and republish.

    The SNAPSHOTS repository (as opposed to the releases repository) allows you to overwrite a similarly numbered version, but your version number should have "-SNAPSHOT" at the end of it.

    0 讨论(0)
  • 2020-11-29 18:18

    I had put a not encrypted password in the settings.xml .

    I tested the call with curl

    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 
    

    and I got the error:

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

    I retrieved my encrypted password clicking on my artifactory profile and unlocking it.

    0 讨论(0)
提交回复
热议问题