项目中 Maven 私服 Nexus 的使用

项目中 Maven 私服 Nexus 的使用

配置认证信息

在Maven的 settings.xml 中的servers节点下添加Nexus认证信息

<server>
	<id>nexus-releases</id>
	<username>admin</username>
	<password>admin</password>
</server>
<server>
	<id>nexus-snapshots</id>
	<username>admin</username>
	<password>admin</password>
</server>

id:配置的服务id
username:Nexus私服用户名
password:Nexus私服登录密码

Snapshots(快照版)与Releases(发行版)
  • Snapshot与Release版本定义如下:
Release: 1.0.0/1.0.0-RELEASE
Snapshot: 1.0.0-SNAPSHOT
  • 在项目pom.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本,没有SNAPSHOT标识的都会发布为RELEASE版本。
  • SNAPSHOT版本会自动加一个时间作为标识,如:1.0.0-SNAPSHOT发布后变成 1.0.0-SNAPSHOT-20190920.191919-1.jar
配置自动化部署

项目 pom.xml 文件配置以下内容

<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<name>Nexus Release Repository</name>
		<url>http://192.168.1.128:8080/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Nexus Snapshot Repository</name>
		<url>http://192.168.1.128:8080/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

注意事项:

  • ID名称必须要与settings.xml中server配置的ID名称保持一致
  • 项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository,否则发布到Nexus Release Repository,并根据ID去匹配授权账号
部署到仓库
mvn deploy
第三方JAR包的上传

Nexus 3.0 不支持页面上传,可使用maven命令:

# mysql-connector-java-8.0.17.jar 为例
mvn deploy:deploy-file
	-DgroupId=mysql
	-DartifactId=mysql-connector-java
	-Dversion=8.0.17
	-Dpackaging=jar
	-Dfile=D:\mysql-connector-java-8.0.17.jar
	-Durl=http://192.168.1.128:8081/repository/maven-3f/
	-DrepositoryId=nexus-releases

注意事项:

  • 上面命令需要作为一行执行,不能有换行
  • maven-3f,单独创建的第三方jar包管理仓库,便于管理维护
  • -DrepositoryId=nexus-releases,对应得是 settings.xml 中配置服务的ID名称
配置代理仓库

项目 pom.xml 文件配置以下内容

<repositories>
	<repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>https://192.168.1.128:8081/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
				<enabled>true</enabled>
			</releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Plugin Repository</name>
            <url>http://192.168.1.128:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

万里sunshine

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

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

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

打赏作者

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

抵扣说明:

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

余额充值