【问题标题】:mvn deploy:deploy-file -- Failed to deploy artifacts: Could not find artifactmvn deploy:deploy-file -- 无法部署工件:找不到工件
【发布时间】:2013-04-25 15:38:05
【问题描述】:

我正在尝试将第 3 方供应商的 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/

在我的 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

我还尝试了通过 Nexus Web 界面使用 GAV 参数“上传工件”:

Group: acme
Artifact: acme
Version: 1.0
Packaging: jar

然后选择并添加 acme-1.0.jar。 这可以很好地完成,但是根据这个 jar 对项目进行“mvn install”会导致:

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。

【问题讨论】:

    标签: maven nexus


    【解决方案1】:

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

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

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

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

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

    我通过查看 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
    

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

    【讨论】:

    • 只是为了澄清......默认情况下,第 3 方存储库是一个发布存储库,因此除非有人将其更改为快照,否则无需将其更改为该存储库。请始终牢记 Nexus Maven 存储库是快照或发布,并使用组将它们混合在一起。
    【解决方案2】:

    登录到 nexus web 控制台并检查公共存储库配置,并查看第 3 方是否在有序组存储库列表中。

    【讨论】:

    • 感谢 Bhushan,但我已经在 Ordered Group Repositories 列表中拥有了第 3 方存储库。不过建议很好。
    猜你喜欢
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2021-10-16
    • 2021-12-09
    • 1970-01-01
    • 2011-11-21
    • 2020-12-03
    • 2013-04-13
    相关资源
    最近更新 更多