mvn deploy:deploy-file - 无法部署工件:找不到工件

Sha*_*ram 7 nexus maven

我正在尝试将第三方供应商的jar添加到我们的内部nexus存储库中.

我尝试使用此命令执行此操作:

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/
Run Code Online (Sandbox Code Playgroud)

在我的settings.xml中使用以下条目:

  <servers>
        <server>
            <id>Nexus</id>
            <username>myusername</username>
            <password>mypassword</password>
        </server>
  </servers>
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

[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]
Run Code Online (Sandbox Code Playgroud)

有什么建议?

一些相关信息...我可以使用此命令安装到我的本地存储库中:

mvn install:install-file 
-DgroupId=acme 
-DartifactId=acme 
-Dversion=1.0 
-Dpackaging=jar 
-Dfile=C:\tmp\acme-1.0.jar
Run Code Online (Sandbox Code Playgroud)

我还使用GAV参数通过Nexus Web界面尝试了"Artifact Upload":

Group: acme
Artifact: acme
Version: 1.0
Packaging: jar
Run Code Online (Sandbox Code Playgroud)

并选择并添加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)
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢...

PS我知道这个问题是非常相似,这一个,但这个问题似乎是使用了詹金斯的URL,而不是一个承上启下的URL.

Sha*_*ram 6

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

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

<proxies>
  <proxy>
    ...
    <nonProxyHosts>myserver</nonProxyHosts>
  </proxy>
</proxies>
Run Code Online (Sandbox Code Playgroud)

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

2)确保您的第三方存储库设置为Release,而不是Snapshot.要执行此操作,请转到Web GUI,选择第三方存储库的"配置"选项卡,并确保将"存储库策略"设置为"发布".

我通过查看catalina.out日志(我在Tomcat中运行nexus作为战争)并看到以下内容找到了这个:

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
Run Code Online (Sandbox Code Playgroud)

通过这两个修复程序,"mvn deploy:deploy-file"命令以及通过Web GUI中的"Upload Artifacts"选项进行上传工作.