利用Nexus搭建Maven私服

私服搭建

Docker Hub链接地址: https://hub.docker.com/r/sonatype/nexus/

docker pull sonatype/nexus
mkdir /data/nexus-data && chown -R 200 /data/nexus-data
docker run -d -p 8081:8081 --name nexus -v /data/nexus-data:/nexus-data sonatype/nexus3​

本地Maven配置

​修改Maven的全局setting.xml文件如下:

文件路径: $MAVEN_HOME/conf/setting.xml

  • mirrors节点加入如下内容
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus</name>
      <url>http://192.168.1.80:8081/repository/maven-public/</url>
    </mirror> 

  • profiles节点加入如下内容
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile> 

 
  • activeProfiles​节点加入
<activeProfile>nexus</activeProfile>​


对于Snapshot的jar,如果想及时的更新,可以在maven参数中加上-U,就可以获得最新的jar包。

本地组件deploy

除了配置本地Maven配置外,还需要在setting.xml文件中加入如下内容:

  • servers节点
    <server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>  

项目的pom.xml文件,加入如下配置:
  <distributionManagement>
      <repository>
          <id>maven-releases</id>
          <url>http://192.168.1.​80:8081/repository/maven-releases/</url>
      </repository>
      <snapshotRepository>
          <id>maven-snapshots</id>
          <url>http://192.168.1.80:8081/repository/maven-snapshots/</url>
      </snapshotRepository>
  </distributionManagement>​
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值