zoukankan      html  css  js  c++  java
  • maven中distributionManagement

    分发构件至远程仓库
    mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库。本地Maven仓库的构件只能供当前用户使用,在分发到远程Maven仓库之后,所有能访问该仓库的用户都能使用你的构件。
    我们需要配置POM的distributionManagement来指定Maven分发构件的位置,如下:
     
    <project>    
      <distributionManagement>    
        <repository>    
          <id>nexus-releases</id>    
          <name>Nexus Release Repository</name>    
          <url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>    
        </repository>    
        <snapshotRepository>    
          <id>nexus-snapshots</id>    
          <name>Nexus Snapshot Repository</name>    
          <url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>    
        </snapshotRepository>    
      </distributionManagement>    
    </project>  
    Maven区别对待release版本的构件和snapshot版本的构件,snapshot为开发过程中的版本,实时,但不稳定,release版本则比较稳定。Maven会根据你项目的版本来判断将构件分发到哪个仓库。
    一般来说,分发构件到远程仓库需要认证,如果你没有配置任何认证信息,你往往会得到401错误。这个时候,如下在settings.xml中配置认证信息:
    <settings>    
      ...    
      <servers>    
        <server>    
          <id>nexus-releases</id>    
          <username>admin</username>    
          <password>admin123</password>    
        </server>    
        <server>    
          <id>nexus-snapshots</id>    
          <username>admin</username>    
          <password>admin123</password>    
        </server>      
      </servers>    
      ...    
    </settings> 
    需要注意的是,settings.xml中server元素下id的值必须与POM中repository或snapshotRepository下id的值完全一致。将认证信息放到settings下而非POM中,是因为POM往往是它人可见的,而settings.xml是本地的。
     

    小结

    本文介绍了Maven仓库,它是什么?本地仓库,远程仓库,中央仓库具体是指什么?并介绍了如何在POM中配置项目层次的仓库,在settings中配置用户层次的仓库,以及mirror。本文还介绍了如何安装构件到本地仓库,如何分发构件至仓库。
     

    如果这里不配置,会报错: 报 错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

  • 相关阅读:
    OnMeasureItem和OnDrawItem的区别和联系
    DockPanel 类
    C# 源码 AForge.NET
    ystem.Windows.Forms.SplitContainer : ContainerControl, ISupportInitialize
    System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....
    System.ComponentModel.Component : MarshalByRefObject, IComponent, IDisposable
    System.Windows.Forms.ListView : Control
    vs2013 密钥_
    系统封装 EasyBoot如何将WIN7安装版提取到光盘
    系统封装 ES3使用方法
  • 原文地址:https://www.cnblogs.com/leodaxin/p/8488419.html
Copyright © 2011-2022 走看看