sonatype-nexus私服的搭建與settings的設置


一、sonatype-nexus私服的docker部署測試

 1.1、查找nexus鏡像

docker search nexus

 1.2、宿主機上創建目錄 /data/nexus3,並增加操作權限

# 創建目錄
mkdir data && mkdir data/nexus3
# 添加修改權限
chmod 777 /data/nexus3/

 1.3、安裝sonatype/nexus3,由於我測試用的虛擬機只有2G內存,所以設置容器的JVM內存為1G

# 1、下載鏡像
docker pull sonatype/nexus3

# 2、啟動容器
docker run -d -p 18081:8081 \
  --volume /data/nexus3:/nexus-data \
  --name nexus \
  -e INSTALL4J_ADD_VM_PARAMS="-Xms1g -Xmx1g -XX:MaxDirectMemorySize=1g"\
  sonatype/nexus3

1.4、nexus3容器啟動OK,可以查看下狀態

 二、設置maven的settings文件,加入私服鏡像源,並配置release/snapshot版本相關的訪問權限

 2.1、settings文件的設置示例

<?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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!--
  <localRepository>/opt/apache-maven/repos</localRepository>
  -->
  <!--
  <localRepository>d:/sxhMavenRepository</localRepository>
   -->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <server>
        <id>releases</id>
        <username>simm</username>
        <password>my@nexus123</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>simm</username>
        <password>my@nexus123</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <name>nexus maven</name>
      <url>http://192.168.1.108:18081/repository/maven-public/</url>
      <mirrorOf>*</mirrorOf>        
     </mirror>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>
  <profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>crop-nexus</name>
                <url>http://192.168.1.108:18081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <url>http://192.168.1.108:18081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
   <activeProfiles>
       <activeProfile>nexus</activeProfile>
   </activeProfiles>
</settings>
View Code

 2.2、項目的POM文件設置release和snapshot的服務地址

<distributionManagement>
        <repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.1.108:18081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <!--nexus3中該配置無效 true:推送的snapshot版本號會生成隨機數保證唯一,false不產生隨機數 -->
            <!-- <uniqueVersion>false</uniqueVersion> -->
            <url>http://192.168.1.108:18081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

 2.3、執行maven的deploy命令,嘗試推送snapshot鏡像到私服

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM