Java 11
我有一个非常基本的 Spring Boot
应用程序,我想在 Nexus
服务器上构建和部署 Artifact 。
mvn clean 部署(从我的本地 Win 10 计算机 - 有效!!!)
mvn clean 部署(来自 Nexus 机器 - 失败???)
mvn clean 部署(来自 Jenkins - 失败???)
当我从本地 Win 10
计算机运行 mvn clean deploy
命令时,所有 Artifact 都会成功部署在远程 Nexus
服务器上,我可以甚至可以查看和浏览它们。
但是当我克隆项目并在 Nexus
和 Jenkins
(Ubuntu
框)已安装,它给我未授权
错误。
我已经将 settings.xml
和 settings-security.xml
从我的本地 Windows
计算机复制到 Ubuntu
(~/.m2
),其中安装了 Nexus
。
我还禁用了防火墙
,只是为了确保没有端口被阻止。
我很困惑如何从远程计算机复制 Artifact 而不是从同一台计算机复制 Artifact 。
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>my-maven-snapshots</id>
<url>http://my-nexus-server/nexus/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>my-maven-releases</id>
<url>http://my-nexus-server/nexus/repository/maven-releases/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:https://johndoe@bitbucket.org/johndoe/todo.git</connection>
<url>https://johndoe@bitbucket.org/johndoe/todo</url>
<developerConnection>scm:git:https://johndoe@bitbucket.org/johndoe/todo.git</developerConnection>
<tag>HEAD</tag>
</scm>
错误(Nexus 安装在此计算机上):
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ todo ---
[INFO] Installing /home/admin/cloned-apps/todo/pom.xml to /home/admin/.m2/repository/com/example/todo/0.0.2-SNAPSHOT/todo-0.0.2-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ todo ---
Downloading from my-maven-snapshots: http://my-nexus-server/nexus/repository/maven-snapshots/com/example/todo/0.0.2-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata com.example:todo:0.0.2-SNAPSHOT/maven-metadata.xml from/to my-maven-snapshots (http://my-nexus-server/nexus/repository/maven-snapshots/): Not authorized , ReasonPhrase:Unauthorized.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for todo 0.0.2-SNAPSHOT:
[INFO]
[INFO] todo ............................................... FAILURE [ 4.622 s]
[INFO] todo-webapp ........................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.973 s
[INFO] Finished at: 2020-04-16T02:39:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project todo: Failed to retrieve remote metadata com.example:todo:0.0.2-SNAPSHOT /maven-metadata.xml: Could not transfer metadata com.example:todo:0.0.2-SNAPSHOT/maven-metadata.xml from/to my-maven-snapshots (http://my-nexus-server/nexus/repository/maven-snapshots/ ): Not authorized , ReasonPhrase: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
最佳答案
mvn clean deploy (from Nexus machine - FAILS ????)
您确定正在从您复制了 settings.xml 的
和 $HOME/.m2
目录下的同一用户运行 mvn clean deploy
settings-security.xml
文件?
此外,您是否尝试将密码直接添加到 settings.xml
中以排除 settings-security.xml
的问题(如果有)?
P.S:避免使用 sudo
权限运行 mvn
命令。
关于java - 无法使用 mvn clean deploy 从同一台计算机将 Artifact 上传到 Nexus,在我的本地 Windows 10 计算机上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61242115/