Reputation: 20163
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...
settings.xml
.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.
settings.xml
, settings/servers/server/id equals ossrh
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:
$M2_HOME/conf/settings.xml
${user.home}/.m2/settings.xml
Here's my setup:
settings.xml
: C:\applications\programming\apache-maven-3.2.2\conf\settings.xml
M2_HOME
is C:\applications\programming\apache-maven-3.2.2
Output for 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] ------------------------------------------------------------------------
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:\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"
##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.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>[email protected]</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:[email protected]:aliteralmind/xbnjava.git</connection>
<url>scm:git:[email protected]:aliteralmind/xbnjava.git</url>
<developerConnection>scm:git:[email protected]: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>
##Full logs for mvn deploy
and mvn deploy -e
##
mvn deploy
output:
[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
(Failure section:)
[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
output:
[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
(Failure section:)
[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
Upvotes: 183
Views: 394638
Reputation: 24472
You should now publish with a user token if you are publishing via OSSRH.
They have changed their account management process.
To get your token do this:
Log In
button on the upper-right corner)Profile
Summary
and select User Token
Access User Token
button and do authentication if neededSee Generate a Token on OSSRH for information.
See a related discussion here.
Upvotes: 0
Reputation: 158
In my case, because of the lack of JAVA_HOME and Path variables. I forgot to add these settings after downloading the Java SDK and it caused this cryptic error.
Upvotes: 0
Reputation: 144
Very old post, but in case someone crawls it and searches for an alternative answer after trying all of the great resources above, here is what worked for me:
In my case, mvn was being packaged from another directory than what was setup in the IDE (jetbrains-idea-ce).
The settings.xml
is being called from the /.m2/settings.xml
, while the version that is triggering mvn package
and mvn deploy
is using another path dpkg-ed from apt, so /usr/share/maven
.
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.17, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-56-generic", arch: "amd64", family: "unix"
What solved it for me is actually modifying /usr/share/maven/conf/settings.xml
<settings>
<server>
<id></id>
<!-- <id> has to be the same as the <id> in pom.xml -->
<username>USERNAME</username>
<password>PASSWORD</password>
</server>
</settings>
Upvotes: 1
Reputation: 1225
I was getting error 401 deploying to Nexus 3 using M2Eclipse and I was able to figure out the root cause.
The problem is that M2Eclipse tries to deploy artifacts in parallel which is not permitted by Nexus. You can find more details in this post.
As a workaround you can deploy with a command line maven installation.
Upvotes: 1
Reputation: 130
In my case, it was an incorrect id in the pom in the distributionManagement
tag. Make sure those match.
<repositories>
...
<repository>
<id>correctId</id>
<url>https://pkgs.dev.azure.com/user/_packaging/user/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>correctId</id>
<url>https://pkgs.dev.azure.com/user/_packaging/user/maven/v1</url>
<name>correctId</name>
</repository>
</distributionManagement>
And ofc. make sure you have and then you have the correct token in your setting.xml in .m2 folder in the server's tag. An IDE's maven in configured correctly (to pick up this config)
<server>
<id>correctId</id>
<username>correctId</username>
<password>secretToken</password>
</server>
Upvotes: 2
Reputation: 2282
When running the staging process in an automated CI/CD pipeline (e.g. via GitLab), check that the variables for username and password in Settings -> CI/CD are set correctly.
If "Protect variable" is checked, check that the branch is also protected. Otherwise, the 401 Unauthorized
error will appear.
Upvotes: 0
Reputation: 2047
In my case, I need install Meven in Eclipse, because by default use the latest version.
Go to Windows -> Preferences -> Maven -> Installations -> add -> Directory
Add my Maven version: C:\apache-maven-3.6.2
Then in Run Configurations -> Maven build
Goals: deploy
User Settings: C:\apache-maven-3.6.2\conf\settings.xml
In Windows, in C:\apache-maven-3.6.2\conf\settings.xml, I set the access to Nexus server:
<servers>
<server>
<id>nexus</id>
<username>aaaaaa</username>
<password>bbbbbbb</password>
</server>
</servers>
Finally press Run
Upvotes: 2
Reputation: 351
I'd had the same issue after trying all these solutions still I'd had the same issue until I checked the settings.xml file
Make sure that the settings.xml file Is .xml extension NOT .xml.txt and that's because I created the file like I create any notepad file.
C:\Users\muham> cd .m2
C:\Users\muham\.m2> ls
I found this output
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/10/2022 1:27 PM repository
-a---- 5/10/2022 1:31 PM 177 settings.xml.txt
That means that my settings.xml file extension was txt
I changed its extension to .xml
C:\Users\muham\.m2> mv settings.xml.txt settings.xml
the output
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/10/2022 1:27 PM repository
-a---- 5/10/2022 1:31 PM 177 settings.xml
Now you can test and hopefully the error will vanish
Upvotes: 0
Reputation: 1134
You can start by trying by typing mvn clean install
in the command line. If you see that you are unable to transfer the artifacts to your local machine due to an authentication error 401, then you might not be using the correct settings.xml for authentication.
You can try mvn clean install -s <path to you settings.xml>
.
In my case, I had the settings.xml on the root folder of my project, so I ran mvn clean install -s ./settings.xml
, and it started successfully downloading the artifacts my projects depend on.
Upvotes: 3
Reputation: 44
Delete all items in .M2 folder. Then run mvn clean package to download all libs. Go to eclipse use maven update. It worked for me.
Upvotes: 0
Reputation: 17697
If you were like me, running maven compile deploy from eclipse's maven run configuration, the issue could be related to eclipse's own embedded maven as described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=562847
The workaround is to run mvn compile deploy from CLI such as bash, or to NOT use embedded maven in the eclipse's maven run configuration, and add an external maven (mine is in /usr/share/mvn), and voila, it'll say BUILD SUCCESS.
Upvotes: 0
Reputation: 34175
I got 401
error when used mvn gpg:sign-and-deploy-file
command and the reason was that
//<maven_home>/conf/settings.xml
//To get `<maven_home>` run `mvn --version`
//for example
/usr/local/Cellar/maven/3.6.3_1/libexec/conf/settings.xml
does not include <server></server>
tag body that you can get via
LogIn to Sonatype -> Profile -> User Token -> Access User Token
//https://oss.sonatype.org/#profile;User%20Token
//it will generate something like
<server>
<id>${server}</id>
<username>{name}</username>
<password>{pass}</password>
</server>
//where `${server}` is the same as `-DrepositoryId` parameter in `mvn gpg:sign-and-deploy-file` command
Upvotes: 0
Reputation: 621
Faced same issue. In my case the reason was pretty stupid - github token I used for authorization was issued for the organization that doesn't own the repo I tried to publish into. So check repo title and ownership.
Upvotes: 0
Reputation: 1
I got the same error when trying to deploy to a Artifactory repository, the following solved the issue for me:
Go to the repository setting in artifactory and enable the point "Force Maven Authentication" and the 401 "Unauthorized" error should be gone. (Of course you need to supply your credentials in the settings.xml file at best in plain text to prevent issues)
I guess by default, even through you supply the right credentials in the settings.xml file, they don't get used and you get the Unauthorized exception.
Upvotes: -1
Reputation: 439
Failed to transfer file:
http://mcpappxxxp.dev.chx.s.com:18080/artifactory/mcprepo-release-local/Shop/loyalty-telluride/01.16.03/loyalty-tell-01.16.03.jar.
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
Solution:
In this case you need to change the version in the pom file, and try to use a new version.
Here 01.16.03 already exist so it was failing and when i have tried with the 01.16.04 version the job went successful.
Upvotes: 1
Reputation: 827
In my case I removed the server logon credentials for central from my setting.
<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>
I don't know why I did that, but its completely wrong since the central maven repo can be accessed anonymously. See my debug output that led to my error identification and resolution.
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://www.localhost:8081/repository/maven-central/ with username=admin, password=***
Upvotes: 0
Reputation: 111
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 ---
Upvotes: 4
Reputation: 186
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.
Upvotes: 3
Reputation: 927
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.
Upvotes: 21
Reputation: 3274
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
Upvotes: 0
Reputation: 11
I was dealing with this running Artifactory version 5.8.4. The "Set Me Up" function would generate settings.xml as follows:
<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>
After using the mvn deploy -e -X switch, I noticed the credentials were not accurate. I removed the ${security.getCurrentUsername()} and replaced it with my username and removed ${security.getEscapedEncryptedPassword()!""} and just put my encrypted password which worked for me:
<servers>
<server>
<username>username</username>
<password>AP56eMPz8L12T5u4J6rWdqWqyhQ</password>
<id>central</id>
</server>
<server>
<username>username</username>
<password>AP56eMPz8L12T5u4J6rWdqWqyhQ</password>
<id>snapshots</id>
</server>
</servers>
Hope this helps!
Upvotes: 1
Reputation: 21
in my case, after encrypting password,I forgot to put settings-security.xml
into ~/.m2。
Upvotes: 2
Reputation: 11
There are two setting.xml in windows.
%MAVEN_HOME%\conf\
%userprofile%\.m2\
If %userprofile%\.m2\setting.xml
takes effect, maven will not access %MAVEN_HOME%\conf\setting.xml
.
Upvotes: 1
Reputation: 1482
Also, after you've updated your repository ids, make sure you run clean as release:prepare
will pick up where it left off. So you can do:
mvn release:prepare -Dresume=false
or
mvn release:clean release:prepare
Upvotes: 0
Reputation: 331
One of the reasons for this error is when repositoryId is not specified or specified incorrectly. As mentioned already it should be the same as in section in settings.xml. Couple of hints... Run mvn with -e -X options and check the debug output. It will tell you which repositoryId it is using:
[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 --
In this case it uses the default value "remote-repository", which means that something went wrong.
Apparently I have specified -DrepositoryID (note ID in capital) instead of -DrepositoryId.
Upvotes: 23
Reputation: 1943
Also had 401's from Nexus. Having tried all the suggestions above and more without success I eventually found that it was a Jenkins setting that was in error.
In the Jenkins configuration for the failing project, we have a section in the 'Post Build' actions entitled 'Deploy Artifacts To Maven Repository'. This has a 'Repository ID' field which was set to the wrong value. It has to be the same as the repository ID in settings.xml for Jenkins to read the user and password fields:
<servers>
<server>
<id>snapshot-repository</id> <!-- must match this -->
<username>deployment</username>
<password>password</password>
</server>
</servers>
Upvotes: 7
Reputation: 185
This is the official explanation from sonatype nexus team about 401 - Unauthorized
I recommend you to read Troubleshooting Artifact Deployment Failures for more information.
Code 401 - Unauthorized
Either no login credentials were sent with the request, or login credentials which are invalid were sent. Checking the "authorization and authentication" system feed in the Nexus UI can help narrow this down. If credentials were sent there will be an entry in the feed.
If no credentials were sent this is likely due to a mis-match between the id in your pom's distributionManagement section and your settings.xml's server section that holds the login credentials.
Upvotes: 3
Reputation: 1760
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.
Upvotes: 10
Reputation: 41
We have had this issue quite recently and found out it was to do with the version of Maven we were using. We were using 3.1.0 and could not upload to nexus, we kept getting 401's, we reverted back to 3.0.3 and the issue went away.
Easiest way to confirm is to work through the maven versions and run "mvn deploy" on your project.
Further details can be found here: https://issues.apache.org/jira/browse/WAGON-421
Upvotes: 3
Reputation: 1818
Some users may have entered the email address instead of the user name by mistake. This may happen unconsciously when the name in the email address is the same as the user name.
Upvotes: 2