1settings.xml

 <!-- 发布用的用户账号deployment/deployment123  是系统默认的发布账号密码   -->  
 <servers>
        <server>  
         <id>frame-releases</id>  
         <username>deployment</username>  
         <password>deployment123</password>  
       </server>  
        <server>  
         <id>frame-snapshots</id>  
         <username>deployment</username>  
         <password>deployment123</password>  
       </server> 
  </servers>
  <mirrors>
    <!-- 工厂的镜像,只有mirrorOf中的工厂要访问,都会自动来查找镜像,  
 如果镜像无法访问就不会再去中央工厂下载,使用*表示所有工厂访问都使用这个  
 镜像,这是推荐的做法  
流程
(1)配置了镜像后,当要下载依赖时,第一步:找到setting.xml中激活的profile下repository里id为xxx的配置,而xxx是镜像里mirrorOf的值

(2)这时会去到到镜像里的url(仓库)里下载依赖

(3)当发现镜像里配置的url(仓库)里下载不到对应的依赖时,会自动去找到maven中默认的id为central,url为中央仓库地址的repository配置,因为central没有配置在镜像中,所以此时可以直接去到maven中央仓库下载依赖包。
 -->  
    <mirror>  
     <id>mirrorId</id>  
     <mirrorOf>*</mirrorOf>  
     <name>Human Readable Name for this Mirror.</name>  
     <url>http://IP:8081/nexus/content/groups/public/</url>  
   </mirror>
  </mirrors>
    <profile>  
         <id>nexusProfile</id>  
          <repositories>  
           <repository>  
             <id>nexusProfile</id>  
            <name>nexus repository</name>  
            <layout>default</layout>  
            <url>http://IP:8081/nexus/content/groups/public/</url>  
            <releases><enabled>true</enabled></releases>  
            <!-- snapshots 默认是关闭的,需手动开启配置-->  
            <snapshots><enabled>true</enabled></snapshots>  
           </repository>  
         </repositories>  
       </profile>  

    <profile>  
         <id>centralProfile</id>  
          <repositories>  
        <repository>  
          <id>central</id>  
          <name>Central Repository</name>  
          <!-- 配置了镜像之后这里的url不再起作用,但其他配置会应用上,  
          此处主要是为了开启snapshots的配置为true ,默认是false关闭 -->  
          <url>https://repo.maven.apache.org/maven2</url>  
          <layout>default</layout>  
          <snapshots>  
            <enabled>true</enabled>  
          </snapshots>  
        </repository>  
      </repositories>  
       </profile>  

    <activeProfiles>  
    <!-- activeProfile 配置的是profile的id,可以激活多个profile-->  
       <activeProfile>nexusProfile</activeProfile>  
    <activeProfile>centralProfile</activeProfile>  
     </activeProfiles>  

2在maven项目pom.xml中配置要发布的仓库地址

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">


.......
    <distributionManagement>
        <repository>
            <id>frame-releases</id>
            <url>http://IP:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>frame-snapshots</id>
            <url>http://IP:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement> 

</project>
posted on 2018-02-25 11:48  2637282556  阅读(156)  评论(0编辑  收藏  举报