搭建-Maven-Nexus私服

Scroll Down

搭建 Maven Nexus私服

编写docker-compose.yml

version: '3.1'
services:
  nexus:
    restart: always
    image: sonatype/nexus3
    container_name: nexus
    ports:
      - 8081:8081
    volumes:
      - /usr/local/docker/nexus/data:/nexus-data

授权nexus目录

chmod 777 /usr/local/docker/nexus/data

最新版本的nexus的进入宿主机目录/usr/local/docker/nexus/data,在admin.password文件中查询admin用户的密码。登陆之后自动提示修改admin的密码

[root@mail data]# ls
admin.password  db             generated-bundles  karaf.pid  log     restore-from-backup
blobs           elasticsearch  instances          keystores  orient  tmp
cache           etc            javaprefs          lock       port


启动nexus镜像

docker-compose up -d

本机没有nexus镜像,会自动从远端拉取,过程会比较慢。

访问nexus私服

http://ip:8081

到这里,maven的私服基于Docker-Compose就搭建完毕了


使用Nexus私服

settings.xml配置Nexus Repository

<?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">
  
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>xxxxxx</password>
        </server>

        <server>
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>xxxxxx</password>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <id>nexus-moodfly</id>
            <mirrorOf>*</mirrorOf>
            <!--* 代表都会去访问私有nexus-->
            <name>Nexus myself</name>
            <url>http://ip:8081/repository/maven-public/</url>
        </mirror>
        <mirror>
            <id>nexus-aliyun</id>
            <mirrorOf>*</mirrorOf>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>moodfly</id>
            <repositories>
                <!-- 私有nexus地址-->
                <repository>
                    <id>nexus</id>
                    <url>http://ip:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <!--插件地址-->
                <pluginRepository>
                    <id>nexus</id>
                    <url>http://ip:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <!--激活moodfly的profile -->
    <activeProfiles>
        <activeProfile>moodfly</activeProfile>
    </activeProfiles>

</settings>

发布项目到Nexus

在Maven项目的pom文件内增加对应的distributionManagement

<distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://ip:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://ip:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
  • SNAPSHOT版本(快照版本)<version>1.0.0-SNAPSHOT</version>

  • RELEASE稳定的版本(发布版本)<version>1.0.0-RELEASE</version>

在项目根目录执行mvn deploy