持续集成 之构建 maven 私服

持续集成 之构建 maven 私服


一、下载Nexus

注意:

  • 根据官网说明,nexus 2.x 可以用 jdk1.7 或者 jdk 1.8,而nexus 3.x 需要用 jdk 1.8,所以我选择了 nexus 2.x

二、安装

1. 解压、配置

  • 因为 nexus 解压后会有两个目录,所以先创建一个 目录 nexus:mkdir nexus

  • #     tar -zxvf nexus-2.11.2-03.tar.gz -C nexus

  • #   cd nexus

  • #   ls

    • nexus-2.11.2-03  sonatype-work (一个是 nexus服务,一个私有库目录)

  • cd nexus-2.11.2-03

  • vi conf/properties

     
       
       
    # Jetty section 
    application-port=8081 
    application-host=0.0.0.0 
    nexus-webapp=${bundleBasedir}/nexus 
    nexus-webapp-context-path=/nexus  
    # Nexus section 
    nexus-work=${bundleBasedir}/../sonatype-work/nexus 
    runtime=${bundleBasedir}/nexus/WEB-INF  

  • 编辑 bin 目录下的 nexus 脚本:设置 RUN_AS_USER=root

  • 防火墙打开 8081 端口,重启防火墙

  • 在浏览器中打开 192.168.135.137:8081/nexus 即可访问

    1

2.页面配置

  • 右上方进行登录,默认初始用户 admin,密码 admin123

  • 在 administration/server 配置邮箱,可用于找回密码

    2

  • 还可以设置用户邮箱地址

    3

  • 用户修改密码

三、仓库类型

5

  • group仓库:包含其他仓库,也就是其他全部仓库的集合

  • hosted宿主仓库:用于发布内部项目构件 或 第三方项目构件

  • proxy:代理仓库:代理公共的远程仓库

1. Hosted 仓库常用类型

  • releases  内部的模块中 release 模块的发布仓库

  • snapshots 发布内部的 SNAPSHOT 模块的仓库

  • 3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

2. 仓库运行流程

  • 如果构建的 Maven 项目本地仓库没有对应的依赖包,那么就会去 Nexus 私服去下载, 如果Nexus私服也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。 Nexus 私服下载成功后再下载至本地 Maven 库供项目引用。

  • 设置代理仓库准许远程下载

3.测试

  • 本地maven的配置文件修改

     
       
       
    <?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>G:\D\maven\repository</localRepository>
    <interactiveMode>true</interactiveMode>
        <offline>false</offline>
        <pluginGroups>
            <pluginGroup>org.mortbay.jetty</pluginGroup>
            <pluginGroup>org.jenkins-ci.tools</pluginGroup>
        </pluginGroups>
        
        <!--配置权限,使用默认用户-->
        <servers>
            <server>
                <id>nexus-releases</id>
                <username>admin</username>
                <password>admin123</password>
            </server>
            <server> 
                <id>nexus-snapshots</id>
                <username>admin</username>
                <password>admin123</password>
            </server>
        </servers>
      <proxies> 
      </proxies>
      <mirrors>
      </mirrors>
      
      <profiles>   
        <profiles>
            <profile>
               <id>edu</id>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                        <jdk>1.6</jdk>
                    </activation>
                    <repositories>
                        <!-- 私有库地址-->
                        <repository>
                            <id>nexus</id>
                            <!-- 仓库组group-->
                        <url>http://192.168.135.137:8081/nexus/content/groups/public/</url>
                            <releases>
                                <enabled>true</enabled>
                            </releases>
                            <snapshots>
                                <enabled>true</enabled>
                            </snapshots>
                        </repository>
                    </repositories>      
                    <pluginRepositories>
                        <!--插件库地址-->
                        <pluginRepository>
                            <id>nexus</id>                      <url>http://192.168.135.137:8081/nexus/content/groups/public/</url>
                            <releases>
                                <enabled>true</enabled>
                            </releases>
                            <snapshots>
                                <enabled>true</enabled>
                           </snapshots>
                        </pluginRepository>
                    </pluginRepositories>
                </profile>
        </profiles>
        
        <!--激活profile-->
        <activeProfiles>
            <activeProfile>edu</activeProfile>
        </activeProfiles>
      </profiles>
    </settings>
  • 项目的 pom.xml(加入以下内容,地址就是 nexus的主机地址)

  •  
       
       
        <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <name>Nexus Release Repository</name>
                <url>http://192.168.135.137:8081/nexus/content/repositories/releases/</url>
            </repository>
            <snapshotRepository>
                <id>nexus-snapshots</id>
                <name>Nexus Snapshot Repository</name>
                <url>http://192.168.135.137:8081/nexus/content/repositories/snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
  • 然后 deploy 就可以在浏览器中看见 啦。。。(如果 deploy 保错,可先进行install在deploy。install是安装到本地库,deploy是发布到代理仓库)

  • 上传第三方库


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值