Maven ant任务部署到公共nexus存储库而不是指定的url

我很难过.我正在使用ant和maven-ant-tasks来构建和部署快照工件(非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正在尝试部署到公共存储库(nexus不允许)而不是指定的快照存储库(请注意nexus.url变量).否构建文件中的位置是指定的公共URL.

为了让事情变得更好奇,在一台机器上,相同的构建脚本成功地使用以下结果部署了相同的工件:

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)都是相同的版本. nexus日志表明两者之间的传入请求不同(其中一个指定快照存储库,另一个指定公共存储库)所以我想在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文件覆盖,并使用为nexus设置的镜像(因此使用错误的只读URL用于部署).

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

决议:

我们将其缩小为< mirrorOf> *< / mirrorOf>设置’*’导致此问题的位置.用特定存储库(例如“central”)替换*可以解决此问题.

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

嗯,这是一个痛苦的追踪失误.

点赞