Artifactory Maven示例失败,并显示401错误代码

时间:2019-01-17 09:03:05

标签: maven artifactory maven-deploy-plugin

我正在本地主机上尝试Artifactory。即使我一直关注他们的tutorial 做他们的 Maven example,我失败,输入401状态代码。这是我得到的错误:

[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

这是位于/Users/my_user_name/.m2中的settings.xml的内容:

<?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>

我已将其添加到pom.xml

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

错误代码401提示我身份验证问题。我想知道settings.xml如何解析凭据,例如${security.getCurrentUsername()}?我什至将普通的用户名和密码放在settings.xml中,但仍然失败。

能否请您告诉我我的设置有什么问题以及如何解决此问题?

2 个答案:

答案 0 :(得分:3)

注意:人工制品6.5.x中有a bug,在版本6.5.2中已解决,该问题阻止正确处理已过滤的资源。

${security.getCurrentUsername()}filtered resource的用法,实际上,它可以将文本文件视为通过FreeMarker模板过滤的文本文件。

当您在人工界面中下载settings.xml文件时,${security.[]}字段将被替换为您当前登录的用户名和加密密码(如果该错误不是当下)。由于该错误,或​​者 if ,您复制/粘贴文本内容而不是下载它们,而settings.xml将包含那些文字上未替换的字符串,并且maven不会替换它们,因为它们在maven中不存在构建上下文。

如您所链接的视频所示,您需要单击download snippet链接,而不是复制文本;否则,您可以复制/粘贴文本,然后需要在其中键入人工的用户名和密码。

答案 1 :(得分:0)

对于那些在这里着陆并尝试使用artefactory云时遇到401的人来说,我的问题是我添加了一个公共镜像部分(Generate Maven Settings链接中没有添加此部分:

Artefactory Set Me Up Dialog

这给了我settings.xml中的一部分:

  <mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>public</name>
      <url>https://{my-domain}.jfrog.io/artifactory/public</url>
      <id>public</id>
    </mirror>
  </mirrors

因此,当我使用此镜像时,我需要在服务器部分添加进一步的身份验证:

       <server>
          <username>{username}</username>
          <password>{encrypted password}</password>
          <id>public</id>
      </server