maven实战笔记-9

    9.5  配置MavenNexus下载构件

     POM中配置Nexus仓库

     <project>

          

           <repositories>

               <repository>

                   <id>nexus</id>

                    <name>Nexus</name>

                    <url>http://localhost:8081/nexus/content/groups/public/</url>

                    <releases>

                         <enabled>true</enabled>

                     </releases>

                     <snapshots>

                         <enabled>true</enabled>

                      </snapshots>

                 </repository>

             </repositories>

                  

             <pluginRepositories>

                 <pluginRepository>

                      <id>nexus</id>

                           <name>Nexus</name>

                    <url>http://localhost:8081/nexus/content/groups/public/</url>

                             <releases>

                                  <enabled>true</enabled>

                              </releases>

                               <snapshots>

                                    <enabled>true</enabled>

                                 </snapshots>

                     </pluginRepository>

             </pluginRepositories>

        </project>

    以上配置只对当前Maven项目有效。使用Profile机制,配置settings.xml可以对所有项目有效。

         settings.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>

                                                        <releases>

                                                                 <enabled>true</enabled>

                                                        </releases>

                                                        <snapshots>

                                                                 <enabled>true</enabled>

                                                        </snapshots>

                                               <repository>

                                     </repositories>

                                     <pluginRepositories>

                                               <pluginRepository>

                                                        <id>nexus</id>

                                                        <name>Nexus</name>

                                                        <url>http://localhost:8081/nexus/content/groups/public/</url>

                                                        <releases>

                                                                 <enabled>true</enabled>

                                                        </releases>

                                                        <snapshots>

                                                                 <enabled>true</enabled>

                                                        </snapshots>

                                               </pluginRepository>

                                     </pluginRepositories>

                            </profile>

                   </profiles>

         </settings>

 

         配置镜像让Maven只使用私服

         <settings>

                  

                  <mirrors>

                            <mirror>

                                     <id>nexus</id>

                                     <mirrorOf>*</mirrorOf>

                                     <url> http://localhost:8081/nexus/content/groups/public/

                            </mirror>

                   </mirrors>

                  

                   <profiles>

                            <profile>

                                     <id>nexus</id>

                                     <repositories>

                                               <repository>

                                                        <id>nexus</id>

                                                        <name>Nexus</name>

                                                        <url> http://localhost:8081/nexus/content/groups/public/</url>

                                                        <releases>

                                                                 <enabled>true</enabled>

                                                        </releases>

                                                        <snapshots>

                                                                 <enabled>true</enabled>

                                                        </snapshots>

                                               <repository>

                                     </repositories>

                                     <pluginRepositories>

                                               <pluginRepository>

                                                        <id>nexus</id>

                                                        <name>Nexus</name>

                                                        <url>http://localhost:8081/nexus/content/groups/public/</url>

                                                        <releases>

                                                                 <enabled>true</enabled>

                                                        </releases>

                                                        <snapshots>

                                                                 <enabled>true</enabled>

                                                        </snapshots>

                                               </pluginRepository>

                                     </pluginRepositories>

                            </profile>

                   </profiles>

                  

                   <activeProfiles>

                            <activeProfile>nexus</activeProfile>

                   </activeProfiles>

                 

</settings>

 

    9.6 部署构件至Nexus  

    9.6.1  使用Maven部署构件至Nexus

     配置Maven部署构件至Nexus:

         <project>

                  

         <distributionManagement>

                   <repository>

                            <id>nexus-releases</id>

                            <name>Nexus Releases Repository</name>

                            <url>http://localhost:8081/nexus/content/repositories/releases/</url>

                   </repository>

                   <snapshotRepository>

                            <id>nexus-snapshots</id>

                            <name>Nexus Snapshots Repository</name>

                            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>

                   </snapshotRepository>

         </distributionManagement>

        

</project>

Nexus的仓库对于匿名用户是只读的。为了能够部署构件,还需要在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>

 

    9.6.2  手动部署第三方构件至Nexus

首先选择一个宿主仓库如3rd party,然后在页面的下方选择Artifact Upload选项卡。如下图所示:

你可能感兴趣的:(maven,职场,学习笔记,休闲,maven笔记)