29

如何配置 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>

此配置在带有 m2e 1.2 的 Eclipse 3.8 中创建错误

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

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

4

3 回答 3

43

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

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

于 2013-01-08T09:51:09.350 回答
29

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>

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

<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>  
于 2013-01-08T14:24:52.267 回答
0

你可以两者都做。

添加maven-release-plugin2.5.3

运行以下命令:

mvn deploy clean:release release:prepare release:perform
于 2017-07-13T14:49:30.990 回答