Docker搭建Maven私有仓库Nexus--配置讲解,Spring Boot 集成

Nexus仓库说明 :

默认仓库:

一般我们刚安装了Nexus之后 , 会自带一些默认的仓库 , 这些仓库已经够我们进行使用了。
请添加图片描述

  1. 默认仓库说明
  • maven-central : maven 中央库,默认从 https://repo1.maven.org/maven2/ 拉取 jar
  • maven-releases : 私库发行版 jar,初次安装请将 Deployment policy 设置为 Allow redeploy
  • maven-snapshots : 私库快照(调试版本)jar
  • maven-public : 仓库分组,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 或项目 pom.xml 中使用
  1. 仓库类型说明
  • group : 这是一个仓库聚合的概念,用户仓库地址选择 Group 的地址,即可访问 Group 中配置的,用于方便
    开发人员自己设定的仓库。maven-public 就是一个 Group 类型的仓库,内部设置了多个仓库,访问顺序取决
    于配置顺序,3.x 默认为 Releases、Snapshots、Central,当然你也可以自己设置。
  • hosted : 私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的 jar 文件
  • snapshots : 本地项目的快照仓库
  • releases : 本地项目发布的正式版本
  • proxy : 代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的 Configuration 页签下 Remote Storage 属性的值即被代理的远程仓库的路径),如可配置阿里云 maven 仓库
  • central : 中央仓库

maven配置Nexus

我们在Spring Boot项目中配置Nexus,并把项目发布到远程仓库呢 , 并且把远程的jar包下载到本地呢

  1. 本地下载一个maven , 并修改maven的setting.xml文件
<!-- 1 : 配置远程仓库的Nexus的登录面,第一个是用户 , 第二个是仓库-->
<servers>
    <server>
        <!--        记住这个ID , 一会要用到-->
        <id>releases</id>
        <username>admin</username>
        <password>czgj-88888888</password>
    </server>
    <server>
        <!--        记住这个ID , 一会要用到-->
        <id>snapshots</id>
        <username>admin</username>
        <password>czgj-88888888</password>
    </server>
</servers>

        <!-- 2. 配置仓库地址 : 远程仓库的地址 -->
<mirrors>
<mirror>
    <id>releases</id>
    <mirrorOf>*</mirrorOf>
    <name>成长轨迹仓库</name>
    <url>http://#{ip}:8081/nexus/repository/maven-public/</url>
</mirror>
</mirrors>

<profiles>

<!-- 3 : 配置JDK-->
<profile>
    <id>jdk-1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <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>

<!-- 4 : 配置默认从远程仓库下载依赖-->
<profile>
    <id>nexus-pr</id>
    <!-- 远程仓库列表 -->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Central</name>
            <!-- 虚拟的URL形式,指向镜像的URL-->
            <url>http://#{ip}:8081/nexus/repository/maven-public/</url>
            <layout>default</layout>
            <!-- 表示可以从这个仓库下载releases版本的构件-->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!-- 表示可以从这个仓库下载snapshot版本的构件 -->
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>


    <!-- 插件仓库列表 -->
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Central</name>
            <url>http://#{ip}:8081/nexus/repository/maven-public/</url>
            <layout>default</layout>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
</profile>

</profiles>

        <!-- 5 : 激活相应的配置-->
<activeProfiles>
<activeProfile>nexus-pr</activeProfile>
<activeProfile>jdk-1.8</activeProfile>
</activeProfiles>

  1. 进入到idea中 设置->构建->Maven-> 更新maven信息

请添加图片描述

  1. 在项目的pom.xml文件中加入依赖,我们就可以实现将项目发布到远程仓库,并从远程仓库下载依赖的操作了。
    <!--    使用成长轨迹的maven库-->
<distributionManagement>
    <repository>
        <!--            这个ID就是刚才setting.xml文件中的id -->
        <id>releases</id>
        <url>http://#{ip}:8081/nexus/repository/maven-releases/</url>
    </repository>
    <!--        仓库的路径-->
    <snapshotRepository>
        <!--            这个ID就是刚才setting.xml文件中的id -->
        <id>snapshots</id>
        <url>http://#{ip}:8081/nexus/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
  1. 我们重启idea,更新 maven

请添加图片描述

  1. 把项目发布到远程仓库

请添加图片描述

  1. 查看远程仓库的依赖
    请添加图片描述

  2. 查看本地仓库的依赖(和远程仓库的一模一样)
    请添加图片描述

  3. 拉取远程仓库的依赖

  • 刷新maven , 或者 install 父项目 , 都会拉取依赖
    请添加图片描述

完毕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

欢乐少年1904

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值