Nexus 私服之三“Maven 与 Nexus 协同工作”
1. Maven 从 Nexus 下载构件
a) 对当前 Maven 项目(项目 pom.xml)
<repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8888/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8888/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>
b) 对所有 Maven 项目(全局 settings.xml)
<profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8888/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8888/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
i. activeProfile
这个元素将 nexus 这个 profile 激活。
ii. 缺点
虽然所有 Maven 项目都是从 Nexus 下载构件,但是会发现 Maven 除了从Nexus 下载构件外,
还会不时低访问中央仓库 central,我们希望的是所有Maven 下载请求都仅仅通过 Nexus,
才能全面发挥私服的作用。
c) 配置镜像让 Maven 只使用私服
可以创建一个匹配任何仓库的镜像,镜像的地址为私服,这样,
Maven 对任何仓库的构件下载请求都会转到私服中。
<mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8888/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://central</url> <release> <enabled>true</enabled> </release> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <release> <enabled>true</enabled> </release> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
i. 解释
仓库及插件仓库配置,它们的 id 都为 central,相当于覆盖了超级 pom 中央仓库的配置,
它们的 url 已经无关紧要了,因为所有请求都会通过镜像访问私服地址。
2. 部署构件至 Nexus
如果只为代理外部公共仓库,那么 Nexus 的代理仓库就已经能够完全满足需要了。
对于另一类 Nexus 仓库“宿主仓库”来说,它们的主要作用是存储组织内部的,或者一
些无法从公共仓库中获得的第三方构件,供大家使用。
a) Maven 部署构件至 nexus
日常开发生成的快照版本构件可以直接部署到Nexus 中策略为 Snapshot 的宿主仓库中,
项目正式发布版本构件应该部署到 Nexus 中策略为 Release 的宿主仓库中。
i. pom.xml 配置
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Releases Repository</name> <url>http://localhost:8888/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshots Repository</name> <url>http://localhost:8888/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
ii. settings.xml 配置(用户名密码是你的登录名和密码)
<servers> <server> <id>nexus-releases</id> <username>lichee</username> <password>lichee323</password> </server> <server> <id>nexus-snapshots</id> <username>lichee</username> <password>lichee323</password> </server> </servers>
b) 手动部署第三方构件至 nexus
Repositories 3rd party Artifact Upload
i. GAV Definition
如果构件是通过 Maven 构建的,那么可以在这个下拉列表中选择 From POM,
否则就选 GAV Parameters(需要用户为该构件定义一个 Maven 坐标)。
ii. Select Artifact(s) to Upload
此按钮从本机选择要上传的构件,然后单击 Add Artifact 按钮将其加入到上传列表中。
Nexus 允许用户一次上传一个主构件和多个附属构件(即 Classifier)。最后,
单击 Upload Artifact(s)按钮将构件上传到仓库中。
(尽可能的把所有配置都给出来了,不过程序员就是懒,那来个更懒的办法,
如有需要请下载附件settings.zip,修改里面用户名、密码、仓库地址,
还有你的Nexus私服地址,替换掉你自己的settings.xml即可。)
相关推荐
Maven Nexus 私服搭建 从零开始,资源下载、安装指导、开发配置说明
Windows 下Nexus搭建Maven私服 Windows 下Nexus搭建Maven私服
Nexus搭建Maven私服 +maven安装步骤
该文档是关于配置maven私服nexus,对maven学习者有很大的帮助
maven 私服 nexus2 nexus3 安装与说明,只有简单的安装,没有详细的配置使用说明
nexus maven私服搭建nexus maven私服搭建nexus maven私服搭建nexus maven私服搭建nexus maven私服搭建nexus maven私服搭建
nexus 搭建 maven仓库nexus 搭建 maven仓库nexus 搭建 maven仓库nexus 搭建 maven仓库nexus 搭建 maven仓库
详细介绍了nexus私服的配置及安装方法
maven 私服 nexus3 安装包,这个版本使用起来有些不方便,不知道是系统退步了,还是个人能力不济
nexus1.9_搭建maven私服,搭建项目管理方便开发
maven maven私服 nexus 私服
关于使用Nexus搭建Maven私服的开发文档。新手了解一下。
我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载和浪费了外网带宽,如果网速慢的话
nexus maven 私服搭建,附带搭建教程。
包含了一个父maven项目和及个子项目,可以作为搭建nexus私服的测试代码
maven使用及Nexus搭建Maven私服
使用Nexus1.8搭建MAVEN私服详细步骤,以及在网页上上传JAR包
linux,搭建maven私服,nexus3.14+maven3.6.3.zip,apache-maven-3.6.3-bin.tar.gz,nexus-3.14.0-04-unix.tar.gz
maven nexus 配置,简要介绍如何配置nexus。。。。。。