根據評論更新:
<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 帳戶
- 使用
~/.m2/jFrog 憑據(用戶名和密碼)初始化檔案夾下的 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
Does anyone know what I have been missing? Why I got the 401 unauthorized error? I have added the credentials in settings.xml, my understanding is it is not required to add any credential in project level.
Any help is appreciated, thanks in advance.
uj5u.com熱心網友回復:
Maven 配置了在大多數情況下都可以使用的內置默認值,并且標準的 Maven 感知存盤庫服務器(如 Nexus 和 Artifactory)將以最少的配置與它們一起使用。
洗掉您擁有的自定義配置maven-deploy-plugin,讓它使用默認設定。相反,為您的服務器添加一個distributionManagement帶有的部分repository,并確保您的~/.m2/settings.xml檔案中有匹配的憑據。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/336826.html
