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

时间:2012-12-11 17:48:47

标签: maven ant nexus maven-ant-tasks

我很难过。我正在使用ant和maven-ant-tasks来构建和部署快照工件(非maven)到远程nexus存储库。构建过程指定存储库的URL。这是运行的蚂蚁目标:

<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)上。

2 个答案:

答案 0 :(得分:2)

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

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

<强>分辨率:

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

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

uggh,这是一个很难追踪的错误。

答案 1 :(得分:0)

这似乎在2.1.4-SNAPSHOT版本中得到解决。