Artifactory maven部署未授权

Artifactory mvn deploy not auhorized

我已经在 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 并输入我的凭据。

谢谢。

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

比较我的设置和你的设置,我认为你需要镜像ID。在我的例子中:nexus-releases

如您在我的附加设置中所见,<server> 定义了一个 ID 为 <id>nexus-releases</id> 的 user/password。

然后在镜像部分,它和id具有相同的服务器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 artifactory。可能是 kuberentes、gcp、aws 等中的错误
  • 使用空的 m2 存储库并确保使用您的 seetinng.xml。您可以将这句话附加到您的 mvn deploy 命令中:
    -s /tmp/my_settings.xml -Dmaven.repo.local=/tmp/m2
  • 尝试使用 linux 而不是 windows。