怎么样创建私服 nexus --- maven配置文件的各个标签的作用是什么

nexus 私服的搭建
可以参考

一、环境搭建

1.下载一个nexus3的镜像

docker pull sonatype/nexus3

2.将容器内部/var/nexus-data挂载到主机/root/nexus-data目录

docker run -d -p 8081:8081 --name nexus --restart=always -v /root/nexus-data:/var/nexus-data sonatype/nexus3

3.关闭防火墙(如果能正常访问就不用做)

systemctl stop firewalld

访问 http://ip:8081,Maven私服启动容器稍微比较慢,等待1分钟即可

默认登陆账号 admin、admin123

二、创建私服仓库

从浏览器输入对应的网址
创建仓库,点击Create repository

然后选择maven2(hosted)

然后输入仓库名称(my-release)

在version policy中选择这个仓库的类型,这里选择release

在Deployment policy中选择Allow redeploy(这个很重要).

三、创建私服账号

点击左侧菜单栏的Users菜单,然后点击Create local user

我这里创建了一个用户,账号密码是:liuwq、abc1234

四、创建代理仓库,将私服的镜像源改成阿里的镜像源

点击 create repository,选择

将阿里云的仓库地址粘贴进去。
然后点开,public的仓库组,将阿里仓库的位置排在central仓库的是上面即可。

在这里插入图片描述

在这里插入图片描述

五、把maven的setting文件改成如下

<mirror> 标签中的<mirrorof> 可以指定repositoryId,从而将mirror和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">
    <!--不使用代理,直接使用阿里的镜像源-->
    <proxies>
    </proxies>
<!--如果需要上传依赖到公司私服,这段代码会派上用场-->
<servers>
    <server>
        <id>nexus</id>
        <username>admin</username>
        <password>123456</password>
    </server>
</servers>

<!--nexus是私服,aliyun是公共仓库地址-->
<mirrors>
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>https://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

    <mirror>
        <id>nexus</id>
        <name>nexus</name>
        <mirrorOf>local</mirrorOf>
        <url>http://192.168.100.176:8001/repository/maven-public/</url>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>aliyun</id>
        <repositories>
            <repository>
                <id>nexus-aliyun</id>
                <name>Nexus aliyun</name>
                <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>

    <!--私服中,配置了阿里的代理仓库在中央仓库前面,因此会先去阿里的镜像中寻找依赖包-->
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>local</id>
                <url>http://192.168.100.176:8001/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>
`
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值