mavenartifactorymaven-deploy-plugin

Artifactory Maven example fails with 401 error code


I'm trying Artifactory on my localhost. Even though I've followed their tutorial to do their Maven example, I fail with 401 status code. Here is the error I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project multi: Failed to deploy artifacts: Could not transfer artifact org.jfrog.test:multi:pom:3.7-20190117.083916-1 from/to snapshots (http://localhost:8081/artifactory/libs-snapshot-local): Failed to transfer file http://localhost:8081/artifactory/libs-snapshot-local/org/jfrog/test/multi/3.7-SNAPSHOT/multi-3.7-20190117.083916-1.pom with status code 401 -> [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 multi: Failed to deploy artifacts: Could not transfer artifact org.jfrog.test:multi:pom:3.7-20190117.083916-1 from/to snapshots (http://localhost:8081/artifactory/libs-snapshot-local): Failed to transfer file http://localhost:8081/artifactory/libs-snapshot-local/org/jfrog/test/multi/3.7-SNAPSHOT/multi-3.7-20190117.083916-1.pom with status code 401

Here is content of settings.xml located in /Users/my_user_name/.m2:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP84FzVbdvwcgreF8m9HT77ESkA"}</password>
      <id>central</id>
    </server>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP84FzVbdvwcgreF8m9HT77ESkA"}</password>
      <id>snapshots</id>
    </server>
  </servers>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://localhost:8081/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://localhost:8081/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://localhost:8081/artifactory/libs-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://localhost:8081/artifactory/libs-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

And I've added this to pom.xml

<distributionManagement>
    <snapshotRepository>
        <id>snapshots</id>
        <name>0e5e20a55438-snapshots</name>
        <url>http://localhost:8081/artifactory/libs-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>

Error code 401 hints me authentication issue. I'm wondering how does settings.xml resolve credentials, e.g. ${security.getCurrentUsername()}? I even put plain username and password in the settings.xml ,but still it failed.

Can you please tell me what's wrong in my settings and how can I fix this issue?


Solution

  • NOTE: there is a bug in artifactory 6.5.x, which was resolved in version 6.5.2, that prevents filtered resource to be correctly processed.

    ${security.getCurrentUsername()} is an usage of a filtered resource, which in artifactory allows to treat text files as filtered via FreeMarker templates.

    When you download the settings.xml file in the artifactory UI, the ${security.[]} fields would have been replaced with your currently logged username and encrypted password (if that bug was not present). Because of the bug, or if you copy/paste the text content instead of downloading, the settings.xml will contain those literal unreplaced strings, and maven would not replace them because they do not exist in the maven build context.

    As shown in the video you linked, you need to click the download snippet link, instead of copying the text; otherwise, you can copy/paste the text and then you need to type your artifactory username and password in it.