【问题标题】:How to configure maven project to deploy both snapshot and releases to Nexus?如何配置 Maven 项目以将快照和版本部署到 Nexus?
【发布时间】:2012-12-22 02:41:03
【问题描述】:

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

【问题讨论】:

    标签: maven deployment nexus


    【解决方案1】:

    您需要区分版本和快照存储库。 &lt;distributionManagement&gt; 只允许一个&lt;repository&gt; 和一个&lt;snapshotRepository&gt; 子级。

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

    【讨论】:

    • 配置文件允许使用不同的 部分。如果你有多个 那么你可以使用不同的配置文件来完成它。
    【解决方案2】:

    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>  
    

    【讨论】:

      【解决方案3】:

      两者都可以。

      添加maven-release-plugin 2.5.3

      运行以下命令:

      mvn deploy clean:release release:prepare release:perform
      

      【讨论】:

      • 这很好,但它需要已经配置了 maven 和项目,这就是问题的关键:如何配置
      猜你喜欢
      • 2018-01-27
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2017-11-09
      相关资源
      最近更新 更多