将构件发布到私有的nexus maven 仓库

1、settings.xml 中配置用户名密码
<server>
    <id>deploymentRepo</id>
    <username>repouser</username>
    <password>repopwd</password>
</server>
2、pom.xml中配置 distributionManagement块,执行deploy就可以了 3、如果要发布到 snapshotRepository的话,只需要保证项目的版本最后是-SNAPSHOT结尾就会在发布的时候自动发布到配置的snapshotRepository下。 默认的nexus用户名是admin密码是admin123,登录后可以看到有一个depolyment用户,可以设置一个密码,然后用depolyment的用户来发布到我们自己的nexus私有仓库。本文使用nexus这个名字作为私服的主机名。如果你也想直接使用nexus访问到私服,可以设置hosts文件。 下面我列出在项目中的pom:
<repositories>
    <!-- 本地稳定版本构件库-->
    <repository>
        <id>releases</id>
        <name>releases</name>
        <url>http://nexus:8081/nexus/content/repositories/releases</url>
    </repository>
    <!-- 本地临时版本构件库-->
    <repository>
        <id>snapshots</id>
        <name>snapshots</name>
        <url>http://nexus:8081/nexus/content/repositories/snapshots</url>
    </repository>
</repositories>


<!-- 发布到本地镜像仓库 -->
<distributionManagement>
    <repository>
        <id>releases</id>
        <name>releases</name>
        <url>http://nexus:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>snapshots</name>
        <url>http://nexus:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>
配合使用profiles可以灵活的区分不同的环境动态设置配置
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <jdbc_driverClass>com.mysql.jdbc.Driver</jdbc_driverClass>
            <jdbc_host>localhost</jdbc_host>
            <jdbc_port>3306</jdbc_port>
            <jdbc_dbname>test</jdbc_dbname>
            <jdbc_username>root</jdbc_username>
            <jdbc_password>123456</jdbc_password>

        </properties>
    </profile>

    <profile>
        <id>linux</id>
        <activation>
            <os>
                <family>linux</family>
            </os>
        </activation>
        <properties>
            <log4j_log_path>/var/log</log4j_log_path>
        </properties>
    </profile>
</profiles>
同时如果直接从远程仓库下载依赖太慢,在开发团队中,使用nexus开启central的proxy仓库是一个很好的办法,开启的办法很简单,就是使用admin登录nexus的后台,然后设置Central的配置,讲下载索引的开关打开,并且将这个仓库添加到Publish的列表中,然后在本地的maven配置文件中,设置mirror。
<mirror>
<id>centralMirror</id>
<mirrorOf>central</mirrorOf>
<name>Central Repository Mirror Server.</name>
<url>http://nexus:8081/nexus/content/repositories/central</url>
</mirror>
 

tips:

本文由wp2Blog导入,原文链接:http://devonios.com/%e5%b0%86%e6%9e%84%e4%bb%b6%e5%8f%91%e5%b8%83%e5%88%b0%e7%a7%81%e6%9c%89%e7%9a%84nexus-maven-%e4%bb%93%e5%ba%93.html

转载于:https://my.oschina.net/yangyan/blog/859172

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值