Maven私有仓库的搭建与使用【nexus的配置与使用】【Mac】

一、下载

官网下载地址
各系统下载地址

二、搭建服务

1,解压好下载的nexus压缩包,会有以下2个文件夹
文件夹
2,进入nexus-3.53.1-02/bin目录下,执行./nexus start 启动服务,第一次启动会下载一些文件会花费较长的时间,请耐心等待
3,nexus是可执行文件,支持的命令参数有以下
Usage: ./nexus {start|stop|run|run-redirect|status|restart|force-reload}
常用命令参数是

  • start 启动服务(后台运行)
  • stop 停止服务
  • status 查看服务状态
  • restart 重新启动服务
    4,启动成功后,默认端口是8081,浏览器访问方式为localhost:8081
    修改默认接口则在nexus-3.53.1-02-mac/nexus-3.53.1-02/etc/nexus-default.properties文件修改application-port
    比如修改默认端口为8083在这里插入图片描述
    5,访问后登录,点击右上角Sign in登录,默认用户名admin,密码会随机生成在nexus-3.53.1-02-mac/sonatype-work/nexus3/password文件中,登录后会要求修改密码
    在这里插入图片描述

三、配置私服

参考文档

四、在Maven中使用私服

1,修改用户目录下.m2/settings.xml

<?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>/Users/username/.m2/repository</localRepository>

    <!-- Apache Maven 配置 -->
    <pluginGroups/>
    <proxies/>

    <servers>
        <server>
            <id>maven-public</id>
            <username>admin</username>
            <password>123456</password>
        </server>
        <server>
            <id>maven-snapshots</id>
            <username>admin</username>
            <password>123456</password>
        </server>
        <server>
            <id>maven-releases</id>
            <username>admin</username>
            <password>123456</password>
        </server>
    </servers>

    <!-- 阿里云镜像 -->
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>

    <!-- 配置: java8, 先从阿里云下载, 没有再去私服下载  -->
    <!-- 20190929 hepengju 测试结果: 影响下载顺序的是profiles标签的配置顺序(后面配置的ali仓库先下载), 而不是activeProfiles的顺序 -->
    <profiles>
        <!-- 全局JDK1.8配置 -->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>


        <!-- 阿里云配置: 提高国内的jar包下载速度 -->
        <profile>
            <id>ali</id>
            <repositories>
                <repository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>

        <profile>
            <id>maven-NEXUS</id>
            <!-- 远程仓库列表 -->
            <repositories>
                <repository>
                    <id>maven-public</id>
                    <name>test</name>
                    <!-- 虚拟的URL形式,指向镜像的URL-->
                    <url>http://localhost:8083/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>

    </profiles>

    <!-- 激活配置 -->
    <activeProfiles>
        <activeProfile>jdk1.8</activeProfile>
        <activeProfile>ali</activeProfile>
        <activeProfile>maven-NEXUS</activeProfile>
    </activeProfiles>
</settings>

2,往私有仓库上传jar包

在这里插入图片描述

3,往私有仓库发布jar包

  1. 可在打包后参考第二步上传jar包
  2. 在需要发布的项目pom文件中添加distributionManagement配置,而后使用idea工具右侧的maven栏,点击deploy发布到远程仓库,而后登录到你的nexus私服就能查看部署的jar包
    • package:完成了项目编译、单元测试、打包功能,但并没有把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库
    • install:完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓3库,但没有布署到远程maven私服仓库
    • deploy:完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库
<distributionManagement>
    <repository>
        <id>maven-releases</id>
        <name>Release Repositories</name>
        <url>http://localhost:8083/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>maven-snapshots</id>
        <name>Snapshot Repositories</name>
        <url>http://localhost:8083/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

在这里插入图片描述

PS如果maven报错

Since Maven 3.8.1 http repositories are blocked.
表示maven3.8.1及以后的不支持http协议
有2个解决方案

  1. 让你的私有仓库地址支持https
  2. 降低maven版本到3.6.3

参考文章

https://blog.csdn.net/zhangleiQAQ/article/details/127904409

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值