利用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>​
發佈了40 篇原創文章 · 獲贊 16 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章