首页 > 其他 > 详细

Maven Nexus私库搭建及使用,你还不会吗?

时间:2020-05-19 18:57:21      阅读:50      评论:0      收藏:0      [点我收藏+]

为什么要使用私库

maven默认去远程中央仓库下载JAR包的,访问国外网络相当慢,如果团队每个人都去下载一遍无疑是网络的浪费,当然也可以添加国内的镜像,如阿里的比较稳定,但如果想添加远程不存在的像第三方公司的JAR包就比较麻烦。

所以,使用私库,第一,开源包只要有一个人下载过其他人就不需要再下载了,直接从私库下载即可。第二,可以用来管理第三方公司的或者远程仓库不存在的JAR包,或者公司不开源的JAR包。

推荐国内稳定的镜像,如阿里的

http://maven.aliyun.com/nexus/content/groups/public/

nexus下载安装

首先去sonatype官网下载nexus包,要下载开源免费版的OSS版,即Open Source Software。

https://www.sonatype.com/nexus-repository-oss

技术分享图片

下载最新的3.X的版本,这里以windows为例进行下载。

下载后点击bin目录中的启动文件即可,默认的端口是8081,访问路径是/,也可以去配置文件中修改,这里以默认。

启动后,打开localhost:8081,nexus默认的用户名是admin/admin123

默认安装有以下这几个仓库,在控制台也可以修改远程仓库的地址,第三方仓库等。

技术分享图片

Maven配置

修改maven主目录conf/setting.xml配置文件。

添加nexus认证的用户名和密码配置信息。

<servers>

????<server>
????? ? ? <id>nexus-releases</id>
????? ? ? <privateKey>admin</privateKey>
????? ? ? <passphrase>admin123</passphrase>
????</server>

????<server>
????? ? ? <id>nexus-snapshots</id>
????? ? ? <privateKey>admin</privateKey>
????? ? ? <passphrase>admin123</passphrase>
????</server>

</servers>

添加mirror镜像

?<mirrors>
????<mirror>
????? ? ? <id>Nexus</id>
????? ? ? <mirrorOf>*</mirrorOf>
????? ? ? <name>Nexus</name>
????? ? ? <url>http://127.0.0.1:8081/repository/maven-public/</url>
?????</mirror>
? </mirrors>

添加私库

<profiles>
	<profile>
	<id>Nexus</id>
	<repositories>
		<repository>
			<id>Nexus</id>
			<name>Nexus</name>
			<url>http://127.0.0.1:8081/repository/maven-public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
		<id>Nexus</id>
		<name>Nexus</name>
		<url>http://127.0.0.1:8081/repository/maven-public/</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
		</pluginRepository>
	</pluginRepositories>
	</profile>
</profiles>

激活私库

<activeProfiles>
????  <activeProfile>Nexus</activeProfile>
</activeProfiles>

发布到私库

技术分享图片

在pom配置文件中添加

<!-- nexus-releases nexus-snapshots与settings.xml中server下的id对应 -->
<distributionManagement>

	<repository>
		<id>nexus-releases</id>
		<name>Nexus Releases Repository</name>
		<url>http://localhost:8081/nexus/content/repositories/releases/</url>
	</repository>

	<snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Nexus Snapshots Repository</name>
		<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
	</snapshotRepository>

</distributionManagement>

在项目上使用命令mvn deploy打包就能发布到私库。

推荐去我的博客阅读更多:

1.Java JVM、集合、多线程、新特性系列教程

2.Spring MVC、Spring Boot、Spring Cloud 系列教程

3.Maven、Git、Eclipse、Intellij IDEA 系列工具教程

4.Java、后端、架构、阿里巴巴等大厂最新面试题

觉得不错,别忘了点赞+转发哦!

Maven Nexus私库搭建及使用,你还不会吗?

原文:https://www.cnblogs.com/javastack/p/12918031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!