nexus私服 和 settings.xml

3,540 阅读3分钟

前言

搞清楚这是啥工具

settings.xml

  • 本地仓库位置
  • 修改远程仓库存储器
  • 认证信息等配置

远程仓库设置

一般maven先会在本地仓库搜索源码,搜索不到的时候会向远程仓库请求。

    // 设置一个中心仓库或多个
    <mirror>    
      <id>nexus</id>    
      <mirrorOf>central</mirrorOf>      // 中央仓库的映射
      <name>nexus mirror.</name>
      <url>http://192.168.20.72:8080/content/groups/public</url>
    </mirror>
    
    <mirrorOf>central</mirrorOf>里是要替代的仓库的id,这里就是会代替central的。如果填*,就会替代所有仓库。

Nexus 配置

  • 项目使用nexus私服的jar包,在项目的pom.xml文件中指定私服仓库
这个在pom.xml、setting.xml都可以配置,引用级别是从pom > setting
<repositories>
      <repository>
          <id>nexus</id>
          <name>nexus</name>
          <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
             <enabled>true</enabled>
         </snapshots>
     </repository>
 </repositories>
————————————————
版权声明:本文为CSDN博主「摩尔__摩尔」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011217058/article/details/79418317
  • 插件仓库同理
<pluginRepositories>
      <pluginRepository>
          <id>nexus</id>
          <name>nexus</name>
          <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
             <enabled>true</enabled>
         </snapshots>
     </pluginRepository>
 </pluginRepositories>
————————————————
版权声明:本文为CSDN博主「摩尔__摩尔」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011217058/article/details/79418317
  • 如果需要本机所有的maven项目都使用私服的组件,可以在setting.xml文件中添加属性,并激活
  <profile>
       <id>Nexus</id>   // 定义一个profiles
       <repositories>
         <repository>   // 定义一个远程仓库
          <id>nexus</id>
          <url>http://localhost:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
         </repository>
       </repositories>
       <pluginRepositories>
         <pluginRepository>     // 定义一个插件仓库
           <id>nexus</id>
           <url>http://localhost:8081/repository/maven-public/</url>
           <releases>
            <enabled>true</enabled>
           </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
         </pluginRepository>
        </pluginRepositories>
     </profile>
  </profiles>
  <!-- 激活 -->
  <activeProfiles>      // 激活
    <activeProfile>Nexus</activeProfile>
  </activeProfiles>
————————————————
版权声明:本文为CSDN博主「摩尔__摩尔」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011217058/article/details/79418317

向远程仓库发布项目

mvn install 可以把远程仓库的代码下载到本地,发布代码可以用 mvn deploy,要发布到 nexus 里,必须通过标签来进行配置。假如版本号是 X.X.X-Releases 会发布到 Release 仓库中,Snapshots 同理。

    <distributionManagement>
        <repository>
            <id>nexus-release</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.20.72:8080/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshots Repository</name>
            <url>http://192.168.20.72:8080/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

参考: