美文网首页
[Maven专题-03] -Maven私服构建

[Maven专题-03] -Maven私服构建

作者: ccczyl2006 | 来源:发表于2019-11-06 20:43 被阅读0次

私服概述

  • 私服是一种特殊的远程仓库,它一般假设在公司局域网内。当Maven下载构件时从私服上取,如果不存在则私服从远程仓库中取缓存在私服上,方便后续人员取用。它的优点如下:
    • 节省外网宽带,构件高效。
    • 有利于在中央仓库不存在的第三方构件和自己生成的构件。
    • 加速构建过程,提供稳定性以及降低中央仓库的负荷等。

私服搭建

  • 选择Ubuntu 18.04平台,openjdk-8以及使用Nexus OSS 3.13.0版本库管理工具, 搭建过程如下:

    #1 下载nexus-3.13.0-01-unix.tar.gz文件至家目录下 官网下载速度奇慢,使用Baidu网盘下载
    #2 解压缩至/opt/目录下,
    yjf@v-box:~$ sudo tar -zxvf nexus-3.13.0-01-unix.tar.gz -C /opt/
    #3 进入/opt/nexus-3.13.0-01/bin目录,执行以下命令运行nexus
    yjf@v-box:/opt/nexus-3.12.0-01/bin$ sudo ./nexus start 
    #4 nexus的常用命令
    #4.1 start  开启 
    #4.2 stop   停止
    #4.3 status 状态
    
  • 成功启动后,使用http://192.168.0.210:8081/#browse/welcome进行访问,进行配置需要登录,默认的用户名和密码为admin:admin123如下图:

  • Nexus仓库的分类:

    • Nexus宿主仓库,主要用于管理第三方构件,分为RELEASE和SNAPSHOT版本。
    • 代理仓库,主要代理远程中央仓库,在本私服上不存在指定构件时从中央仓库上直接下载。
    • 仓库组:可以聚合以上两种仓库形成列表,作为仓库供maven配置下载,仓库便利的顺序按配置从上到下遍历。
  • Nexus宿主仓库建立

    • 点击上图的配置按钮,选择Repositories连接,并点击Create Repository,在弹出的选择列表中选择maven2(hosted)即可进行创建,配置如下:

  • Nexus代理仓库建立

    • 步骤同上,在点击Create Repository,在弹出的选择列表中选择maven2(proxy)即可进行创建,配置如下:

  • Nexus 仓库组建立

    • 步骤同上,在点击Create Repository,在弹出的选择列表中选择maven2(group)即可进行创建,配置如下:

Maven配置私服

  • 拉取构件,主要分在项目中配置和setting.xml中配置两种方式。

    <!-- 项目中配置,只针对此项目有效 
      1 未配置任何仓库的情况下,由于超级POM的作用,默认配置中央仓库。
      2 在项目中覆盖配置中央仓库,配置如下:  该方式配置与超级POM中的中央仓库合并 首先在该仓库中找 找不到则在中央仓库中找。
    -->
    <repositories>
        <repository>
          <id>jboss</id>
            <name>JBoss Repository</name>
            <url>http://192.168.0.210:8081/repository/jboss-central/</url>   
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>false</enabled></snapshots>
            <layout>default</layout>
        </repository>
    </repositories>
    
    <!-- 
      3 在setting.xml中配置profile, 覆盖超级POM中的中央仓库和插件仓库的配置
    -->
    <profiles>
      <profile>
            <id>nexusProfile</id>
            <repositories>
                <repository>
                  <id>central</id>
                    <name>Central Repository</name>
                    <url>http://192.168.0.210:8081/repository/maven-public/</url>   
                    <snapshots><enabled>false</enabled></snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                  <id>central</id>
                    <name>Central Repository</name>
                    <url>http://192.168.0.210:8081/repository/maven-public/</url>   
                    <snapshots><enabled>false</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
      <activeProfile>nexusProfile</activeProfile>
    </activeProfiles>
    
    
  • 推送构件到私服仓库,需要配置如下:

    <!-- setting.xml 配置如下:-->
    <servers>
        <server>
          <id>nexus-server</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
    <distributionManagement>
        <snapshotRepository>
            <id>nexus-server</id>
            <name>snapshots-hosted</name>
            <url>http://192.168.0.210:8081/repository/snapshot-hosted/</url>
        </snapshotRepository>
        <!-- 推送正式版本时请务必在pom.xml文件中版本号中删除SNAPSHOT字样 否则产生400错误 -->
        <repository>
            <id>nexus-server</id>
            <name>release-hosted</name>
            <url>http://192.168.0.210:8081/repository/release-hosted/</url>
        </repository>
    </distributionManagement>
    

相关文章

  • [Maven专题-03] -Maven私服构建

    私服概述 私服是一种特殊的远程仓库,它一般假设在公司局域网内。当Maven下载构件时从私服上取,如果不存在则私服从...

  • Maven实战之nexus

    使用专门的Maven仓库管理软件Nexus构建Maven私服。 nexus下载地址 https://www.son...

  • Maven私服搭建

    什么是maven私服? 工程中如何使用? 如何接入maven私服? 了解maven私服 分为本地和远程 远程包括:...

  • Maven入坑(一) Hello world

    Maven 专题 Maven 是什么 Maven 是 Java平台的构建管理,依赖管理和项目信息管理的工具. 相当...

  • Docker之MAVEN私服

    Docker之MAVEN私服 目录 nexus简单介绍 Docker安装MAVEN nexus Maven nex...

  • Maven(5)Nexus

    前言 Maven是Java项目管理的利器,使用私服来管理Maven仓库是Maven使用的一条最佳实践。私服是内网的...

  • maven私服

    1、配置本地maven settings.xml 使用私服 2、发布jar到私服配置本地maven setting...

  • Ubuntu server下搭建Maven私服Nexus

    Ubuntu server下搭建Maven私服Nexus Maven私服Nexus的作用,主要是为了节省资源,在内...

  • maven私服管理

    maven工程使用私服中需要添加repository 私服会有密码,所以需要在maven的settings文件中加...

  • Gradle初探(三):发布项目到Nexus资源库

    4. 发布项目 在公司开发中,如果采取Maven这种项目构建方式的,一般都会架设一个Nexus Maven私服在公...

网友评论

      本文标题:[Maven专题-03] -Maven私服构建

      本文链接:https://www.haomeiwen.com/subject/ocepbctx.html