Nexus架构Maven私服

  • 下载镜像
  • 创建存储
  • 部署容器
  • 编写Maven配置文件
  • 编写Maven项目pom文件

 

(一)下载镜像

#> docker pull sonatype/nexus3

 

(二)创建存储

#> mkdir /sre/nexus-data && chown -R 200 /sre/nexus-data

 

(三)部署容器

#> docker run -d -p 8081:8081 --name nexus -v /sre/nexus-data:/nexus-data sonatype/nexus3

 

(四)编写Maven配置文件

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<pluginGroups>

</pluginGroups>

<proxies>

</proxies>

<servers>
  
 <server>  
  <id>nexus-releases</id>  
  <username>admin</username>  # 默认用户名admin 
  <password>admin123</password>  # 默认用户密码
 </server>  
 <server>  
  <id>nexus-snapshots</id>  
  <username>admin</username>  
  <password>admin123</password>  
 </server>   
 
</servers>


<mirrors>
  
 <mirror> 
      <id>nexus</id> 
      <mirrorOf>*</mirrorOf> 
      <name>Nexus Mirror</name> 
      <url>http://ip-address:8081/repository/maven-public/</url> 
 </mirror> 
</mirrors>

 
 <profiles>
  
 <profile> 
      <id>nexus</id> 
      <repositories> 
        <repository> 
          <id>nexus</id> 
          <name>local private nexus</name> 
          <url>http://ip-address:8081/repository/maven-public/</url> 
          <releases> 
            <enabled>true</enabled> 
          </releases> 
          <snapshots> 
            <enabled>false</enabled> 
          </snapshots> 
        </repository> 
        <repository> 
          <id>nexus</id> 
          <name>local private nexus</name> 
          <url>http://ip-address:8081/repository/maven-public/</url> 
          <releases> 
            <enabled>false</enabled> 
          </releases> 
          <snapshots> 
            <enabled>true</enabled> 
          </snapshots> 
        </repository> 
 
      </repositories> 
      <pluginRepositories> 
        <pluginRepository> 
          <id>nexus</id> 
          <name>local private nexus</name> 
          <url>http://ip-address:8081/repository/maven-public/</url> 
          <releases> 
            <enabled>true</enabled> 
          </releases> 
          <snapshots> 
            <enabled>false</enabled> 
          </snapshots> 
        </pluginRepository> 
        <pluginRepository> 
          <id>nexus</id> 
          <name>local private nexus</name> 
          <url>http:/ip-address:8081/repository/maven-public/</url> 
          <releases> 
            <enabled>false</enabled> 
          </releases> 
          <snapshots> 
            <enabled>true</enabled> 
          </snapshots> 
        </pluginRepository> 
      </pluginRepositories> 
    </profile> 
 </profiles>
 <activeProfiles> 
    <activeProfile>nexus</activeProfile> 
  </activeProfiles> 
 
</settings>

 

(五) 编写Maven项目pom文

<distributionManagement>
  <repository>
    <id>nexus</id>
    <name>local private nexus</name>
    <url>http://ip-address:8081/repository/maven-public/</url>
  </repository>
</distributionManagement>