使用Nexus搭建Maven私服仓库

使用Nexus搭建Maven私服仓库

一、为什么要使用私服

在项目团队实际开发中,往往Maven仓库需要集中管理。建立内部的私服仓库,能够很好地解决这一问题,既方便对Maven坐标进行管理,也方便仓库Jar的下载。本文主要介绍Nexus来搭建Maven私服仓库,Nexus是一款非常好用的私服搭建工具。

二、Nexus主要功能

他可以用来进行指定私服的中央地址、将自己的Maven实际项目推送到私服主流地址、从私服下载中央仓库的项目进行过程中的索引、从私服仓库下载所依赖的组件、将第三方项目jar上传到私服供其他开发组员使用。

开启了Nexus服务之后进行访问url链接:http://localhost:8182/nexus/,之后进行登录,用户名密码分别是:admin/admin123。

然后点击菜单栏Repositories按钮:


使用Nexus搭建Maven私服仓库


一般所使用的仓库种类:

(1)hosted类型的仓库,用于内部项目发布的仓库

(2)releases内部的模块中release模块的发布仓库

(3)snapshots发布内部的SNAPSHOT模块的仓库

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

(5)proxy类型的仓库,从远程中央仓库中找到数据的仓库

(6)group类型的仓库,组仓库用来方便我们开发人员进行设置的仓库

三、使用项目索引

下载Maven项目索引,项目索引是为了操作的人员可以在私服站点查找依赖所开启的功能


使用Nexus搭建Maven私服仓库


保存之后后台可以运行一个任务,通过点击菜单栏Scheduled Tasks选项即可看到有个任务在运行。下载成功之后,Maven索引就可以使用了,在搜索栏输入要搜索的项,就可以找到相关度的信息。比如搜索spring-core


使用Nexus搭建Maven私服仓库


就可以检索出相关的信息,包括怎么配置互相需要的信息。如果我们想使用这个私服仓库,先应该在pom进行配置私服信息,指定仓库


<repositories>

<repository>

nexus

<name>nexus/<name>

http://192.168.3.162:8182/nexus/content/groups/public/

<releases>

<enabled>true/<enabled>

<snapshots>

<enabled>true/<enabled>


指定插件仓库

<pluginrepositories>

<pluginrepository>

nexus

<name>nexus/<name>

http://192.168.3.162:8182/nexus/content/groups/public/

<releases>

<enabled>true/<enabled>

<snapshots>

<enabled>true/<enabled>

完成了这些操作之后,本项目就可以下载私服组件了。

全局settings.xml需要修改,配置用户认证:

<server> /<server>

nexus

<username>admin/<username>

<password>admin123/<password>

<server> /<server>

Snapshots

<username>admin/<username>

<password>admin123/<password>

<server> /<server>

Releases

<username>admin/<username>

<password>admin123/<password>

上面使用的setting.xml 中的

<server> /<server>

nexus... 和

<mirror> /<mirror>

nexus ... 中的id值保持一致


SnapshotsReleases 是用于maven项目中 pom.xml文件里面的如下内容,注意id值保持一致

<distributionmanagement>

<repository>

Releases

http://私服地址/repository/maven-releases/

<snapshotrepository>

Snapshots

http://私服地址/repository/maven-snapshots/

四、发布项目到私服

发布项目快照到私服上命令行下执行:mvn clean deploy -Dmaven.test.skip=true



分享到:


相關文章: