【问题标题】:Artifactory mvn deploy not auhorizedArtifactory Maven 部署未授权
【发布时间】:2020-01-14 22:05:15
【问题描述】:

我已经在 kubernetes 集群上安装了 artifactory-oss,但我无法使用 maven 在其上进行部署。

当我运行mvn deploy 时出现此错误

.0-SNAPSHOT/maven-metadata.xml from/to snapshots (https://artifactory.adibox.be/artifactory/libs-snapshot-local): Not authorized -> [Help 1]
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>be.adibox</groupId>
    <artifactId>adiboxorm</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <modules>
        <module>annotations</module>
    </modules>

    <distributionManagement>
        <snapshotRepository>
            <id>snapshots</id>
            <name>artifactory-oss-artifactory-0-snapshots</name>
            <url>https://artifactory.adibox.be/artifactory/libs-snapshot-local</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    </dependencies>


</project>

这是我的 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()!"<myencryptedpassword>"}</password>
      <id>central</id>
    </server>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"<myencryptedpassword>"}</password>
      <id>snapshots</id>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>libs-snapshot</name>
      <url>https://artifactory.adibox.be/artifactory/libs-snapshot</url>
      <id>libs-snapshot</id>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>https://artifactory.adibox.be/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>https://artifactory.adibox.be/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>https://artifactory.adibox.be/artifactory/libs-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>https://artifactory.adibox.be/artifactory/libs-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>

</settings>

起初,artifactory 生成的 URL 是 https://artifactory.adibox.be:80/artifactory/libs-snapshot,但我遇到了 SSL 错误。我删除了:80,导致上面指定的错误。

知道有什么问题吗? 是不是因为 Artifactory 部署在 Kubernetes 集群上?

我可以通过访问在浏览器中查看工件列表 https://artifactory.adibox.be/artifactory/libs-snapshot-local 并输入我的凭据。

谢谢。

【问题讨论】:

  • 您是否尝试在 settingx.xml 中明确输入用户名/密码只是为了确保您的帐户有效
  • 是的,我尝试以明文形式使用用户名、电子邮件、明文密码、加密密码的所有组合。我只是没有尝试“转义密码”,因为我不确定 getEscapedEncryptedPassword 实际上在做什么。
  • 我猜这意味着你可以连接,对吧?也许您需要查看权限:您的帐户必须被授权才能部署新工件(某种写入或部署权限)
  • “我猜这意味着你可以连接,对吧?”。我会说不。也许我没有正确解释它,但如果我设置明确的用户名和密码,我会得到完全相同的错误“未授权”。另外,我尝试连接的用户被标记为“管理员”。

标签: maven artifactory


【解决方案1】:

我在 gcp 上部署 Nexus 时遇到了类似的错误。

比较我的设置和你的设置,我认为你需要镜像 id。就我而言:nexus-releases

正如您在我附加的设置中看到的那样,&lt;server&gt; 定义了一个 ID 为 &lt;id&gt;nexus-releases&lt;/id&gt; 的用户/密码。

然后在镜像部分,它的has和id与server id的值相同:nexus-releases

<settings>
  <pluginGroups></pluginGroups>
  <proxies></proxies>
  <servers>
    <server>
      <id>nexus-releases</id>
      <username>jane</username>
      <password>doe</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus-releases</id>
      <mirrorOf>*</mirrorOf>
      <name>central</name>
      <url>https://mynexus.com/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles></profiles>
</settings>

最后在部署时,这个 id nexus-releases 也是必需的:

mvn deploy:deploy-file -DgeneratePom=false -DrepositoryId=nexus-releases -Durl=https://mynexus.com/repository/maven-releases/ -DpomFile=pom.xml -Dfile=myjar-1.0.0.jar

无论如何,如果错误仍然存​​在,我建议您重现问题的步骤。如果无法重现问题,则无法找到解决方案。

  • 尝试使用 localhost 工件。可能是 kuberentes、gcp、aws 等中的错误
  • 使用空的 m2 存储库并确保使用了您的 seetinng.xml。您可以将此句子附加到您的 mvn deploy 命令:
    -s /tmp/my_settings.xml -Dmaven.repo.local=/tmp/m2
  • 尝试使用 linux 而不是 windows。

【讨论】:

  • “确保使用你的seetinng.xml”。这就是诀窍。我在某处使用了一个不起眼的全局 settings.xml。感谢您的提示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
  • 2015-10-31
  • 2018-07-20
  • 2017-11-05
相关资源
最近更新 更多