You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Maven构件到jFrog时报401 Unauthorized错误但实际上传成功如何解决

问题根因

  1. maven-deploy-plugin配置缺失repositoryId:你在插件中硬编码了部署仓库地址,但没有配置<repositoryId>参数,Maven无法匹配到settings.xml中对应id的凭据,拉取远端maven-metadata.xml时用匿名访问触发401。
  2. SNAPSHOT版本部署到Release仓库规则冲突:你当前构件版本是0.0.6-SNAPSHOT快照版本,而插件配置的部署地址是Release仓库,jFrog默认禁止Release仓库存储快照版本,即使临时上传成功,后续元数据同步也会失败。
  3. 冗余配置冲突:你已经配置了<distributionManagement>,完全不需要自定义deploy-file目标,默认的deploy生命周期会自动处理版本匹配、仓库选择、凭据匹配逻辑,自定义配置反而覆盖了默认规则导致异常。

解决方法

最简方案(推荐)

删除pom.xml中自定义的maven-deploy-plugin配置,保留distributionManagement即可,执行mvn deploy时Maven会自动:

  • 根据当前版本是否带-SNAPSHOT自动选择快照/正式仓库
  • 自动匹配distributionManagement中仓库id对应的settings.xml凭据
  • 自动处理元数据合并和构件上传

保留自定义deploy配置的修复方案

如果需要保留自定义deploy-file配置,补充两个配置项:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-deploy-plugin</artifactId>
  <executions>
    <execution>
      <phase>deploy</phase>
      <goals>
        <goal>deploy-file</goal>
      </goals>
      <configuration>
        <packaging>jar</packaging>
        <generatePom>true</generatePom>
        <!-- 补充repositoryId,和settings.xml、distributionManagement中对应仓库的id一致 -->
        <repositoryId>snapshots</repositoryId>
        <!-- 快照版本改为快照仓库地址 -->
        <url>https://mycompany.jfrog.io/artifactory/my-app-libs-snapshot/</url>
        <artifactId>${project.artifactId}</artifactId>
        <groupId>${project.groupId}</groupId>
        <version>${project.version}</version>
        <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
      </configuration>
    </execution>
  </executions>
</plugin>

额外说明

构件能成功上传是因为jFrog的部署鉴权和元数据拉取鉴权是独立的,你部署的权限校验通过,但是拉取元数据时因为没有携带凭据触发401,不影响构件本身上传,但会导致Maven构建标记为失败。

内容的提问来源于stack exchange,提问作者Haifeng Zhang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 15:15:05