maven学习之pom.xml或settings.xml对nexus的配置(转)

Posted 牧野流冰87

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven学习之pom.xml或settings.xml对nexus的配置(转)相关的知识,希望对你有一定的参考价值。

(1)在POM中配置Nexus仓库


    <project>
         ...
         <repositories>
            <repository>
                 <id>nexus</id>
                 <name>Nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public/<url>
                 <release><enabled>true</enabled></release>
                 <snapshots><enabled>true></enabled></snapshots>
             </repository>
        </repositories>
        <pluginRepositories>
             <pluginRepository>
                 <id>nexus</id>
                 <name>Nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public/<url>
                 <release><enabled>true</enabled></release>
                 <snapshots><enabled>true></enabled></snapshots>
              </pluginRepository>
         </pluginRepositories>
         ...
    </project>
   

上述配置只对当前项目有效,若需让本机所有Maven项目均使用Mavne私服,应该在setting.xml中进行配置。
    
 

(2)在setting.xml中配置Nexus仓库


    <settings>
          ...
          <profiles>
                <profile>
                    <id>nexus</id>
                    <repositories>
                        <repository>
                          <id>nexus</id>
                          <name>Nexus</name>
                         <url>http://localhost:8081/nexus/content/groups/public/<url>
                          <release><enabled>true</enabled></release>
                          <snapshots><enabled>true></enabled></snapshots>
                        </repository>
                     </repositories>
                     <pluginRepositories>
                        <pluginRepository>
                            <id>nexus</id>
                            <name>Nexus</name>
                          <url>http://localhost:8081/nexus/content/groups/public/<url>
                            <release><enabled>true</enabled></release>
                            <snapshots><enabled>true></enabled></snapshots>
                       </pluginRepository>
                     </pluginRepositories>
                </profile>
           </profiles>
           <activeProfiles>
               <activeProfile>nexus</activeProfiles>
           </activaProfiles>

    </settings>

 

activeProfiles用来激活。 

 

 

(3) 配置镜像让Maven只使用私服
   

   <settings>
          ...
          <mirrors>
              <mirror>
                  <id>nexus</id>
                  <mirrorOf>*<?mirrorOf>
                 <url>http://localhost:8081/nexus/content/groups/public/</url>
              </mirror>
          </mirrors>
          <profiles>
                <profile>
                    <id>nexus</id>
                    <repositories>
                        <repository>
                          <id>central</id>
                          <name>http://central</name>                       
                          <release><enabled>true</enabled></release>
                          <snapshots><enabled>true></enabled></snapshots>
                        </repository>
                     </repositories>
                     <pluginRepositories>
                        <pluginRepository>
                            <id>central</id>
                            <name>http://central</name>                          
                            <release><enabled>true</enabled></release>
                            <snapshots><enabled>true></enabled></snapshots>
                       </pluginRepository>
                     </pluginRepositories>
                </profile>
           </profiles>
           <activeProfiles>
               <activeProfile>nexus</activeProfiles>
           </activaProfiles>
            ...
    </settings>

只要mirrorOf中的工厂需要下载jar,都会自动来找该镜像。如果镜像地址有,就下载下来。若镜像地址没有,mirrorOf中的工厂也不会到中央资源库下载,而是由镜像去下载。这是推荐做法。若镜像下载不到,就下载失败。 

























































































以上是关于maven学习之pom.xml或settings.xml对nexus的配置(转)的主要内容,如果未能解决你的问题,请参考以下文章

SpringCloud gateway学习之helloWorld

maven学习之继承

Hibernate学习之单向多对一映射

Maven入门2-pom.xml文件与settings.xml文件

Spring框架学习之--搭建spring框架

maven 配置文件 settings.xml pom.xml