zoukankan      html  css  js  c++  java
  • 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镜像到私服

     

     

  • 相关阅读:
    Mysql 库表
    Mysql (二)
    SQLAlchemy
    Mysql 测试题
    jquery
    抽屉 演示
    前端项目
    JavaScript
    Html Css  练习
    Pandas之DataFrame——Part 3
  • 原文地址:https://www.cnblogs.com/MrSi/p/14016451.html
Copyright © 2011-2022 走看看