天天看點

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>

              </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>

                          <id>central</id>

                          <name>http://central</name>                       

                            <id>central</id>

                            <name>http://central</name>                          

     </settings>

隻要mirrorof中的工廠需要下載下傳jar,都會自動來找該鏡像。如果鏡像位址有,就下載下傳下來。若鏡像位址沒有,mirrorof中的工廠也不會到中央資源庫下載下傳,而是由鏡像去下載下傳。這是推薦的做法。若鏡像下載下傳不到,就下載下傳失敗。