maven - mvn 部署 :deploy-file -- Failed to deploy artifacts: Could not find artifact

标签 maven nexus

我正在尝试将 3rd 方供应商的 jar 添加到我们的内部连接存储库中。

我尝试使用此命令这样做:

mvn deploy:deploy-file 
-DgroupId=acme 
-DartifactId=acme 
-Dversion=1.0 
-Dpackaging=jar 
-Dfile=C:\tmp\acme-1.0.jar 
-DrepositoryId=Nexus 
-Durl=http://myserver:8888/nexus/content/repositories/thirdparty/

在我的 settings.xml 中有以下条目:
  <servers>
        <server>
            <id>Nexus</id>
            <username>myusername</username>
            <password>mypassword</password>
        </server>
  </servers>

但我收到此错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:
deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts:
 Could not find artifact acme:acme:jar:1.0 in Nexus (http://myserver:8888/nexus/c
ontent/repositories/thirdparty) -> [Help 1]

有什么建议?

一些相关资料...
我可以使用以下命令很好地安装到我的本地存储库:
mvn install:install-file 
-DgroupId=acme 
-DartifactId=acme 
-Dversion=1.0 
-Dpackaging=jar 
-Dfile=C:\tmp\acme-1.0.jar

我还使用 GAV 参数通过 Nexus 网络界面尝试了“Artifact 上传”:
Group: acme
Artifact: acme
Version: 1.0
Packaging: jar

并选择并添加 acme-1.0.jar。
这完成得很好,但项目上的“mvn install”取决于这个 jar 结果:
Could not find artifact acme:acme:jar:1.0 in Nexus (http://myserver:8888/nexus/content/groups/public)

我的 pom 包含:
<repositories>
  <repository>
    <id>Nexus</id>
    <url>http://myserver:8888/nexus/content/groups/public</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
  </repository>
</repositories>

任何帮助非常感谢...

PS 我知道这个问题与 this one 非常相似,但问题似乎是使用 jenkins url,而不是 nexus url。

最佳答案

回答我自己的问题。我解决了这个问题如下:

1)如果您在代理服务器后面(即您在 maven settings.xml 中设置了代理服务器)但您的 nexus 服务器是内部的,您可能需要在 settings.xml 中将 nexus 服务器添加为 nonProxyHost,例如

<proxies>
  <proxy>
    ...
    <nonProxyHosts>myserver</nonProxyHosts>
  </proxy>
</proxies>

我意识到我需要这样做,因为 "mvn deploy:deploy-file"我正在运行的命令似乎根本没有到达 nexus 存储库。
例如,我可以在 settings.xml 的 server 部分更改 repo id、用户名或密码,但仍然得到完全相同的错误。我还可以将 deploy 命令中的 url 更改为乱码(例如更改为 -Durl=notexist ),甚至完全关闭我的 nexus 存储库,但仍然会出现相同的错误。

2) 确保您的 3rd 方存储库设置为 Release,而不是 Snapshot。
为此,请转到 Web GUI,选择 3rd 方存储库的配置选项卡,并确保将存储库策略设置为发布。

我通过查看 catalina.out 日志(我在 Tomcat 中将 nexus 作为 war 运行)并看到以下内容发现了这一点:
ERROR org.sonatype.nexus.rest.ContentPlexusResource - Got exception during processing request "PUT http://myserver:888/nexus/content/repositories/thirdparty/acme/acme/1.0/acme-1.0.pom": Storing of item thirdparty:/acme/acme/1.0/acme-1.0.pom is forbidden by Maven Repository policy. Because thirdparty is a SNAPSHOT repository

有了这 2 个修复程序,“mvn deploy:deploy-file”命令和通过 Web GUI 中的“Upload Artifacts”选项上传都可以工作。

关于maven - mvn 部署 :deploy-file -- Failed to deploy artifacts: Could not find artifact,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16219052/

相关文章:

maven - 使用 Maven 元数据发布 Ivy 快照

api - 是否可以通过创建日期通过API删除Nexus信息库中的docker镜像?

maven-2 - 如何使用 SBT 从 Nexus 检索快照依赖项?

python - Nexus pypi 存储库 "Could not find a version that satisfies the requirement"

maven - 在添加 Hibernate 元模型类后在 Maven 模块中使用 IntelliJ 时,JUnit 测试失败并出现 Java 错误

gradle - 如何获得我的Nexus存储库以下载最新的工件?

java - 如何使用Maven创建Camel项目?

Java 11-Kotlin 注解处理器

java - 在maven项目中保存java文件失败

java - Atlassian 插件无法编译,安装时缺少软件包