【发布时间】:2021-12-11 04:07:59
【问题描述】:
根据评论更新:
<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 项目(项目名称是 my-second-app)
- 我已经设置了 jFrog 帐户
- 使用 jFrog 凭据(用户名和密码)初始化文件夹
~/.m2/下的 settings.xml,并指定发布和快照的 URL - 我在项目 my-app 中添加了以下插件:
<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 deploy时,项目显示 401 Unauthorized 错误,但工件已部署并且可以在 jFrog 包中找到。 - 我在项目my-second-app中添加了依赖,运行时可以下载依赖
mvn install
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>0.0.6-SNAPSHOT</version>
</dependency>
[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 中添加了凭据,我的理解是不需要在项目级别添加任何凭据。
任何帮助表示赞赏,在此先感谢。
【问题讨论】:
-
您通常不需要
maven-deploy-plugin节中的任何业务。相反,您应该在distributionManagement.repository中定义一个服务器(并在您的.m2/settings.xml中定义匹配的凭据)。 -
@chrylis-cautiouslyoptimistic- 嗨,chrylis,我在我的 pom 中有设置,我已经把它放到了问题中。这是否意味着我不需要在 maven-deploy-plugin 块中指定 url?
-
只定义distributionManagement,而不是使用maven-install-plugin、maven-deploy-plugin...就像你所做的...
-
嗨 chrylis-cautiouslyoptimistic- 和 khmarbaise 谢谢你们两个,你们的建议很有魅力,如果你愿意,请发表评论作为答案,我会为他们投票。再次感谢您。