Maven ant 任务部署到公共(public)关系存储库而不是指定的 url

标签 maven ant nexus maven-ant-tasks

我难住了。我正在使用 ant 和 maven-ant-tasks 构建快照 Artifact (非 maven)并将其部署到远程 nexus 存储库。构建过程指定存储库的 url。这是运行的 ant 目标:

<target name="shared_resources_war_deploy" depends="shared_resources_war">
    <artifact:pom id="sharedResourcesPom" file="${resourcesdir}/shared-resources-pom.xml" />
    <echo message="**************************${nexus.url}*************************" />
    <artifact:deploy file="${resourcesdir}/shared-resources.war">
        <remoteRepository url="${nexus.url}">
            <authentication username="${nexusUserName}" password="${nexusUserPassword}" /> 
        </remoteRepository>
        <pom refid="sharedResourcesPom"/>
    </artifact:deploy>
</target>

结果:
shared_resources_war_deploy:
     [echo] **************************http://${nexusIP}:8081/nexus/content/repositories/snapshots*************************
[artifact:deploy] Deploying to http://${nexusIP}:8081/nexus/content/groups/public
[artifact:deploy] [INFO] Retrieving previous build number from nexus
[artifact:deploy] Uploading: com/xactsites/shared-resources/13.1.19-SNAPSHOT/shared-resources-13.1.19-20121211.172831-28.war to repository nexus at http://${nexusIP}:8081/nexus/content/groups/public
[artifact:deploy] Transferring 2K from nexus
[artifact:deploy] An error has occurred while processing the Maven artifact tasks.
[artifact:deploy]  Diagnosis:
[artifact:deploy]
[artifact:deploy] Error deploying artifact 'com.xactsites:shared-resources:war': Error deploying artifact: Failed to transfer file: http://${nexusIP}:8081/nexus/content/groups/public/com/xactsites/shared-resources/13.1.19-SNAPSHOT/shared-resources-13.1.19-20121211.172831-28.war. Return code is: 400
[artifact:deploy]

BUILD FAILED
C:\Users\11_1_15\build.xml:561: The following error occurred while executing this line:
C:\Users\11_1_15\build.xml:551: Error deploying artifact 'com.xactsites:shared-resources:war': Error deploying artifact: Failed to transfer file: http://${nexusIP}:8081/nexus/content/groups/public/com/xactsites/shared-resources/13.1.19-SNAPSHOT/shared-resources-13.1.19-20121211.172831-28.war. Return code is: 400

由于某些超出我理解的原因,maven 正试图部署到公共(public)存储库(nexus 不允许)而不是指定的快照存储库(注意 nexus.url 变量)。构建文件中没有指定公共(public) URL。

更奇怪的是,在一台机器上,相同的构建脚本成功地部署了相同的 Artifact ,结果如下:
shared_resources_war_deploy:
     [echo] **************************http://${nexusIP}:8081/nexus/content/repositories/snapshots*************************
[artifact:deploy] Deploying to http://${nexusIP}:8081/nexus/content/repositories/snapshots
[artifact:deploy] [INFO] Retrieving previous build number from remote
[artifact:deploy] Uploading: com/xactsites/shared-resources/13.1.19-SNAPSHOT/shared-resources-13.1.19-20121211.172031-27.war to repository remote at http://${nexusIP}:8081/nexus/content/repositories/snapshots
[artifact:deploy] Transferring 2K from remote
[artifact:deploy] Uploaded 2K
[artifact:deploy] [INFO] Retrieving previous metadata from remote
[artifact:deploy] [INFO] Uploading repository metadata for: 'snapshot com.xactsites:shared-resources:13.1.19-SNAPSHOT'
[artifact:deploy] [INFO] Uploading project information for shared-resources 13.1.19-20121211.172031-27
[artifact:deploy] [INFO] Retrieving previous metadata from remote
[artifact:deploy] [INFO] Uploading repository metadata for: 'artifact com.xactsites:shared-resources'

BUILD SUCCESSFUL

实际使用指定 URL 的位置。在比较两台机器时,ant(1.8.1 版)和 maven-ant-tasks(2.1.3)都是同一个版本。关系日志表明传入的请求在两者之间是不同的(其中一个指定快照存储库,另一个指定公共(public)存储库),所以我想将此错误固定在 Maven 上。但是,我无法确定会导致这种情况的任何差异。

这是怎么回事?!

更新:

在嗅探数据包后,我们发现来自 maven 的请求被发送到:/nexus/content/groups/public/com/xactsites/shared-resources/13.1.19.2/shared-resources-13.1.19.2.war HTTP/1.1,在发送请求之前确认 maven 正在更改 URL。因此,解决此问题的任何努力都可以集中在 maven(而不是 nexus)上。

最佳答案

经过一些痛苦的研究和一位同事的侥幸错字开辟了一条新的探索途径,我们找到了原因。本质上,如果 M2/M2_HOME 环境变量设置为指定 here ,然后远程存储库 url 被我们的 settings.xml 文件中的 URL 覆盖,并使用为 nexus 设置的镜像(因此使用错误的只读 URL 进行部署)。

这似乎是使用 <distributionManagement> 的 pom 中的问题。元素以及使用 <remoteRepository> ant 文件中的元素。已经有a bug filed for this .

分辨率:

我们将范围缩小到拥有 <mirrorOf>*</mirrorOf>设置“*”导致此问题的位置。将 * 替换为特定存储库(例如“中央”)可解决此问题。

同样,不设置 M2 环境变量也可以解决此问题,因为它无法访问 settings.xml 文件来获取 URL。当然,如果您在运行部署时依赖于 settings.xml 中的一些其他内容,则您不会希望采用这种方法。

ugh,这是一个令人痛苦的错误。

关于Maven ant 任务部署到公共(public)关系存储库而不是指定的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825701/

相关文章:

java - Maven 配置文件和 Artifact 版本

maven - 具有Maven,Jenkins,Nexus的基础架构

javascript - 替换 JavaScript 文件中的 Maven Archetype 属性

maven - 使用 Maven 打包

java - Ant 与 hudson war

java - 如果依赖包具有相同命名空间的类,如何使 ant 构建失败

ant - 将 war 文件部署到托管 weblogic 服务器到给定的路径位置

maven - 收集 Maven 构建指标,例如花费的时间,构建是否成功

java - STS : run as -> maven install error

java - 由于 rsa 公钥无效,无法从 Nexus 下载工件