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):
[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]
According to this sonatype support page:
"If you are receiving a 401 it is because maven is sending the wrong login credentials, or no credentials at all."
Below are the steps I've taken, below that are my full settings.xml
and pom.xml
files, and below that are the full logs from mvn deploy
and mvn deploy -e
.
Any ideas would be appreciated. I am just hitting wall after wall with Maven.
I followed sonatype's checklist when receiving a 401 error:
Checklist item 1. Make sure your username/password is correct by logging into the Nexus UI. If curl is installed on your machine, you can try deploying an artifact with...
- I successfully logged in and out of the sonatype.org website, using the user/pass in
settings.xml
.
- I attempted to use
curl
to manually deploy an artifact, with the command
[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
but got this error:
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.
I ran it again with the -k
option, and this time got only this:
Couldn't read data from file "pom.xml", this makes an empty POST.
I've never used curl before, so I'm at a loss on what to do with this information.
Checklist item 2. If there is no error output, ensure your user privileges are correctly configured on the server. Make sure to drop the repo you just created.
I don't know what "drop" means. I believe my privileges are properly installed, as I received this message from sonatype:
and I have successfully put these items onto the server via mvn deploy
in the past couple days.
The project's settings:
Checklist item 3. Make sure you have configured a server in settings.xml
and that the server id is identical to the distribution repository id in pom.xml.
- In
settings.xml
, settings/servers/server/id equals ossrh
- In
pom.xml
, distributionManagement/snapshotRepository/id equals ossrh
(full files are at the bottom)
Checklist item 4. Make sure your settings.xml is in the correct place (normally it’s _~/.m2/settings.xml). You can check this by running mvn help:effective-settings.
According to Maven's settings reference, settings.xml must be in one of two locations:
- The Maven install:
$M2_HOME/conf/settings.xml
- A user’s install:
${user.home}/.m2/settings.xml
Here's my setup:
settings.xml
: C:applicationsprogrammingapache-maven-3.2.2confsettings.xml
M2_HOME
is C:applicationsprogrammingapache-maven-3.2.2
Output for mvn help:effective-settings
:
[C:applicationsutilitiescurl]
[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:Usersjeffy.m2
epository</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] ------------------------------------------------------------------------
Checklist item 5. If the server is using https but the URL in your POM is http, you might get 401 as well.
I don't understand which url it's referring to.
Checklist item 6. Use the latest version of Maven, as there is a known issue regarding 401: MNG-4469
I am using the latest version:
[C:]mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:42-04:00)
Maven home: C:applicationsprogrammingapache-maven-3.2.2
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:applicationsprogrammingjdk_7_51jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
------------------
Full settings.xml
and pom.xml
files
(Full logs for mvn deploy
and mvn deploy -e
below)
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.son