如何配置maven项目以将快照和发布部署到Nexus?

时间:2013-01-08 09:20:22

标签: maven deployment nexus

如何配置maven项目以将快照和发布部署到Nexus?

<distributionManagement>
    <repository>
        <id>InternalReleases</id>
        <name>Internal Releases</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>InternalSnapshots</id>
        <name>Internal Snapshots</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
    </repository>
</distributionManagement>

此配置在Eclipse 3.8中使用m2e 1.2

创建错误
Project build error: Non-parseable POM D:\Workspaces\W\Parent\pom.xml: Duplicated tag: 'repository' (position: START_TAG 
 seen ...

当pom的版本以-SNAPSHOT为后缀并且在RELEASE时部署到InternalReleases存储库时,我希望将工件部署到InternalSnapshots存储库。这应该使用相同的pom.xml文件并执行相同的mvn deploy命令。

3 个答案:

答案 0 :(得分:33)

您需要区分版本和快照存储库。 <distributionManagement>只允许一个<repository>和一个<snapshotRepository>孩子。

http://maven.apache.org/pom.html#Distribution_Management

答案 1 :(得分:25)

pom.xml配置示例

<!-- http://maven.apache.org/pom.html#Distribution_Management -->
<distributionManagement>
    <snapshotRepository>
        <id>InternalSnapshots</id>
        <name>Internal Snapshots</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>InternalReleases</id>
        <name>Internal Releases</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
    </repository>
</distributionManagement>

默认Nexus安装的.m2 / settings.xml片段

<server>   
    <id>thirdparty</id>   
  <username>deployment</username>
  <password>deployment123</password>
</server>
<server>
  <id>InternalReleases</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>  
<server>
  <id>InternalSnapshots</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>  

答案 2 :(得分:0)

你可以做到这两点。

添加maven-release-plugin 2.5.3

运行以下命令:

  

mvn deploy clean:发布版本:准备发布:执行