zoukankan      html  css  js  c++  java
  • 本地 Maven项目部署到Nexus Repository

    配置Nexus Repository

    1. 打开WEB管理界面:http://localhost:8081/nexus/index.html
    2. 点击右上角Log In进行登录,默认帐号:admin、密码:admin123
    3. 点击左侧Repositories项 -> central仓库 -> Configuration -> Download Remote Indexes=True -> Save,表示下载远程仓库的索引。
    4. 右键central仓库 -> Update Index,更新远程仓库索引到本地,这一步能够加速本地索引。

       说明:

    • 新搭建的neuxs环境只是一个空的仓库, 需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。 找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。右键仓库 -> Update Index,更新远程仓库索引到本地,这一步能够加速本地索引
    • 新建公司的内部仓库,步骤为 Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,另外把Deployment Policy设置为Allow Redeploy
    • Nexus中仓库组的概念是Maven没有 的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据 groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者 proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。


    在项目中配置Nexus Repository的信息

    项目pom文件配置distributionManagement (这个可以从Repository的Summary里直接copy)

       <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    

     settings.xml配置账号密码。注意server的id与repository的id必须对应

    <servers>
        <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

    用户名密码明文写在文件里不好,可以用下面的办法:
    step 1.先随意定义一个种子, windows下测试, settings-security.xml 这个文件必须放到.m2目录, 否则会提示找不到

    localhost$ mvn --encrypt-master-password 123asdadfafdadf
     {BHe/qKN8q30HBG3bAGbYLOVLnAqVRkzjb9/7yWs+Ks0=}
    
    vim ~/.m2/settings-security.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <settingsSecurity>
       <master>{BHe/qKN8q30HBG3bAGbYLOVLnAqVRkzjb9/7yWs+Ks0=}</master>
    </settingsSecurity>

    step 2.最终生成

    mvn --encrypt-password 你的密码
    {RxLx1asdfiafrjIHfXZDadfwveda23avsdv=}
    
    vim ~/.m2/settings.xml
    
    <server>
         <id>internal</id>
         <username>54chen</username>
         <password>{RxLx1asdfiafrjIHfXZDadfwveda23avsdv=}</password>
    </server>

    mvn的版本要在2.1.0以上才行。

    发布到Nexus Repository

    命令行形式, 执行

    mvn deploy:deploy-file -Durl=http://192.168.0.4:8081/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty -Dfile=jmxspi.jar -DgroupId=oracle.as -DartifactId=jmxspi -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true  

    在Eclipse里,

    创建一个新的Maven Build,

    Name随便起,Base directory使用项目的路径, 如 ${workspace_loc:some-project}, Gloals 填  deploy -Dmaven.test.skip=true 然后Run

    如果需要强制更新maven repository, 后面加一个-U参数, 如

    deploy -Dmaven.test.skip=true -U

    阻止将模块发布到Nexus Repository

    在开发中, 一些模块, 例如最后产生的服务器部署模块, 是不需要发布到Nexus Repository的, 这时候需要在模块的pom中加入以下build配置, 在对整个项目执行deploy的时候, 就不会将这个模块发布到Nexus Repository

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>X.Y</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 相关阅读:
    python Elementtree 生成带缩进格式的xml文件
    Tacotron2论文阅读笔记
    opencv3 7.3 重映射 仿射变换
    numpy.ndarray类型方法
    ubuntu安装百度输入法
    gitlab--cicd实践pytest和flask接口化
    django搭建完毕运行显示hello django
    django搭建
    服务器内存
    python安装第三方库aiohtpp,sanio失败,pip install multidict 失败问题
  • 原文地址:https://www.cnblogs.com/milton/p/4391292.html
Copyright © 2011-2022 走看看