首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在部署maven工件时出现"401未经授权“错误

在部署maven工件时出现"401未经授权“错误
EN

Stack Overflow用户
提问于 2021-10-25 16:59:07
回答 2查看 4.6K关注 0票数 0

基于注释的更新:

代码语言:javascript
复制
  <distributionManagement>
    <repository>
      <id>releases</id>
      <name>Releases</name>
      <url>https://mycompany.jfrog.io/artifactory/my-app-libs-release</url>
    </repository>

    <snapshotRepository>
      <id>snapshots</id>
      <name>Snapshots</name>
      <url>https://mycompany.jfrog.io/artifactory/my-app-libs-snapshot/</url>
    </snapshotRepository>
  </distributionManagement>

原版:

我的目标是处理端到端的maven存储库部署和依赖项导入。

我正在努力将maven项目(项目名为my-app)工件部署到jFrog中,然后将工件作为依赖项添加到另一个maven项目(项目名是我的第二个应用程序)。

我已经用account

  • Initialized凭证(用户名和密码)在文件夹~/.m2/下安装了jFrog

  • settings.xml,并指定了用于发布的URL和快照

  • ,我在project app中添加了以下插件:

代码语言:javascript
复制
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <executions>
            <execution>
              <id>make-a-jar</id>
              <phase>compile</phase>
              <goals>
                <goal>jar</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <executions>
            <execution>
              <phase>install</phase>
              <goals>
                <goal>install-file</goal>
              </goals>
              <configuration>
                <packaging>jar</packaging>
                <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>
        <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>
                <url>https://mycompany.jfrog.io/artifactory/my-app-libs-release</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>

当我运行mvn install时,项目会显示401个未经授权的错误,但是工件是部署的,可以在jFrog包中找到。

代码语言:javascript
复制
    <dependency>
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <version>0.0.6-SNAPSHOT</version>
  </dependency>

代码语言:javascript
复制
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default) on project my-app: Failed to retrieve remote metadata com.mycompany.app:my-app:0.0.6-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.mycompany.app:my-app:0.0.6-SNAPSHOT/maven-metadata.xml from/to remote-repository (https://myurl.jfrog.io/artifactory/my-app-libs-release): authentication failed for https://mycompany.jfrog.io/artifactory/my-app-libs-release/com/mycompany/app/my-app/0.0.6-SNAPSHOT/maven-metadata.xml, status: 401 Unauthorized -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

有人知道我错过了什么吗?为什么我得到401未经授权的错误?我已经在settings.xml中添加了凭据,我的理解是在项目级别上不需要添加任何凭据。

如能提供任何帮助,我们将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-25 17:54:49

Maven配置了内置的默认设置,在大多数情况下都能工作,标准的Maven感知存储库服务器(如Nexus和Artifactory )将以最小的配置与它们一起工作。

去掉maven-deploy-plugin的自定义配置,让它使用默认设置。相反,为服务器添加一个带有repositoryrepository部分,并确保您的~/.m2/settings.xml文件中有匹配的凭据。

票数 2
EN

Stack Overflow用户

发布于 2022-07-13 07:00:18

在我的例子中,重点是id:repository.id和server.id必须是相同的。

pom.xml:

代码语言:javascript
复制
<distributionManagement>
    <repository>
        <id>cloud-3party</id>
        <name>cloud-3party</name>
        <url>xxx</url>
    </repository>
</distributionManagement>

apaphe-maven-3.6.3/conf/seting.xml

代码语言:javascript
复制
<server>
  <id>cloud-3party</id>
  <username>xxx</username>
  <password>xxx</password>
</server>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69712014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档