让Maven项目使用Nexus作为远程仓库的settings.xml配置
让maven项目使用nexus作为远程仓库有两种方式,第一种是在项目的pom.xml中进行更改,让单个项目使用nexus仓库;另一种是通过修改maven的配置文件settings.xml进行更改,让所有项目都使用nexus仓库。
进入maven安装目录的conf文件夹打开,修改settings.xml文件。
1.服务器配置
- <server>
- <id>nexus-releases</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- <server>
- <id>nexus-snapshots</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- </servers>
id:这是Server的ID(不是登录进来的user),与Maven想要连接上的repository/mirror中的id元素相匹配。
username,password:这两个元素成对出现,表示连接这个server需要验证username和password。在nexus中,默认管理员用户名为admin,密码为admin123。
这里使用两个服务器配置,分别对应release和snapshot。
2.镜像
- <mirrors>
- <mirror>
- <id>nexus-releases</id>
- <mirrorOf>*</mirrorOf>
- <url>http://localhost:8081/nexus/content/groups/public</url>
- </mirror>
- <mirror>
- <id>nexus-snapshots</id>
- <mirrorOf>*</mirrorOf>
- <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
- </mirror>
- </mirrors>
id,name:唯一的镜像标识和用户友好的镜像名称。id被用来区分mirror元素,并且当连接时候被用来获得相应的证书。
mirrorOf:镜像所包含的仓库的Id。例如,指向Maven central仓库的镜像(http://repo1.maven.org/maven2/),设置这个元素为central。更多的高级映射例如repo1,repo2 或者*,!inhouse都是可以的。没必要一定和mirror的id相匹配。在这里mirrorOf项当然应该使用*,以表明是所有仓库都会被镜像到指定的地址。
url:镜像基本的URL,构建系统将使用这个URL来连接仓库。这里应该添nexus仓库的地址,地址可以在nexus仓库页面中找到。
3.配置
- <profiles>
- <profile>
- <id>nexus</id>
- <repositories>
- <repository>
- <id>nexus-releases</id>
- <url>http://nexus-releases</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- <repository>
- <id>nexus-snapshots</id>
- <url>http://nexus-snapshots</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>nexus-releases</id>
- <url>http://nexus-releases</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </pluginRepository>
- <pluginRepository>
- <id>nexus-snapshots</id>
- <url>http://nexus-snapshots</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
profile项代表maven的基本配置。按照maven的一贯尿性,很多xml的配置项都会有一个配置项的复数形式作为父节点,以保证该配置项可以配置多个。在profiles项中,当然也可以配置多个profile,不过在这里配一个就够了。下面介绍profile项的各个子节点。
id:用来确定该profile的唯一标识。
repositories/repository:用以规定依赖包仓库的相关信息。在下属节点中,id就不用多说了;URL是指仓库地址,这里使用伪造的地址,否则即使设置了mirror,maven也有可能会直接从中央仓库下载包;releases和snapshots放在一块说吧,这两个节点下属的enable节点用以规定对应的依赖包是否对当前策略有效,假如将snapshot的enable项设为disable,则不会下载snapshot包,这两个节点还有updatePolicy,checksumPolicy和layout属性,这里就不多介绍了,有兴趣的查查文档吧。
pluginRepositories/pluginRepository:用以规定插件仓库的相关信息。其下属节点与repository的相同,不多说了。
4.当前启用配置
- <activeProfiles>
- <activeProfile>nexus</activeProfile>
- </activeProfiles>
用以规定当前启用的配置,将对应profile的ID加入到这一项即可使profile生效。
5.完整配置
- <?xml version="1.0" encoding="UTF-8"?>
- <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
- <pluginGroups></pluginGroups>
- <proxies></proxies>
- <servers>
- <server>
- <id>nexus-releases</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- <server>
- <id>nexus-snapshots</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- </servers>
- <mirrors>
- <mirror>
- <id>nexus-releases</id>
- <mirrorOf>*</mirrorOf>
- <url>http://localhost:8081/nexus/content/groups/public</url>
- </mirror>
- <mirror>
- <id>nexus-snapshots</id>
- <mirrorOf>*</mirrorOf>
- <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
- </mirror>
- </mirrors>
- <profiles>
- <profile>
- <id>nexus</id>
- <repositories>
- <repository>
- <id>nexus-releases</id>
- <url>http://nexus-releases</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- <repository>
- <id>nexus-snapshots</id>
- <url>http://nexus-snapshots</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>nexus-releases</id>
- <url>http://nexus-releases</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </pluginRepository>
- <pluginRepository>
- <id>nexus-snapshots</id>
- <url>http://nexus-snapshots</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
- <activeProfiles>
- <activeProfile>nexus</activeProfile>
- </activeProfiles>
- </settings>
转载:http://blog.csdn.net/u014527058/article/details/50906343
转载于:https://www.cnblogs.com/yhcreak/p/6603578.html
让Maven项目使用Nexus作为远程仓库的settings.xml配置相关推荐
- 让maven项目使用nexus作为远程仓库
让maven项目使用nexus作为远程仓库有两种方式,第一种是在项目的pom.xml中进行更改,让单个项目使用nexus仓库:另一种是通过修改maven的配置文件settings.xml进行更改,让所 ...
- 【Maven学习】Nexus OSS私服仓库的备份与迁移
背景 在上一篇博客 [Maven学习]Nexus OSS私服仓库的安装和配置 中,我们已经在机房搭建好了新的Nexus OSS私服仓库.下面是两个版本的Nexus OSS私服仓库的对比图. 老的Nex ...
- maven 打包部署时访问远程仓库中没有的jar
maven 打包部署时访问远程仓库中没有的jar maven构建项目 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页.如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文 ...
- git同一项目使用多个远程仓库
2019独角兽企业重金招聘Python工程师标准>>> git同一项目使用多个远程仓库 某些场合,一个git项目需要能同时使用两个甚至多个远程仓库,比如国内+国外.测试环境+生产环境 ...
- Git 本地项目添加多个远程仓库
Git 本地项目添加多个远程仓库 第一种方式: 1. 添加一个远程库 名字不能是origin git remote add 17MOX http://git.17byh.com/17MOX ...
- 关于配置远程仓库gitee无法连接配置微服务的问题
关于配置远程仓库gitee无法连接配置微服务的问题 最近在配置config-server微服务时,在gitee新建仓库并且将项目配置放置于仓库内.重构完毕后发现居然无法找到url,接下来就首先看一下具 ...
- Maven配置环境变量、修改本地仓库、修改settings.xml以及添加为settings.xml配置镜像仓库
一.配置环境变量 配置maven环境变量 在我的电脑-------属性-------高级系统设置---------环境变量---------系统变量--------新建 变量名:MAVEN_HOME变 ...
- Maven的settings.xml配置详解
Maven的settings.xml配置详解 1 基本介绍 maven的两大配置文件:settings.xml和pom.xml.其中settings.xml是maven的全局配置文件,pom.xml则 ...
- AndroidStudio上传自己的项目到Bintray jCenter远程仓库(解决400错误)
请注明出处http://blog.csdn.net/qq_23179075/article/details/71123452 我们在AS中要使用别人开源库基本都是用下面的方式: compile 'or ...
最新文章
- 奇异值的物理意义是什么?强大的矩阵奇异值分解(SVD)及其应用
- 创建Cocoapods私有库
- iOS 查询数组中的对象
- python json包_python编程 之 json包
- Java IO流学习总结二:File
- AI让边缘更智能,边缘让AI无处不在
- python程序可以在任何安装了解释器_Python解释器新手安装教程
- leetcode题库522 --最长特殊序列 II
- 是时候该了解下Unity3D了
- 帝国CMS7.5二次元COS漫画分享漫展网站源码
- 2019年win10最精简版本——win10企业2019长期服务版本下载和激活密钥
- unity学习笔记-3dmax人型动画导入unity需要注意的事项
- 键盘模拟文件尾EOF
- 人们为什么会相信伪科学?人类喜欢依赖心理捷径
- 数据结构和算法(32)之背包问题
- 使用 GitHub Actions 来构建应用程序
- ISP—图像调试实习生(第10天)
- 新装修的房子多久能入住
- Sherman-Morrison-Woodbury,SMW恒等式
- 客户机操作系统已禁用 cpu。请关闭或重置虚拟机。_Win10竟然内置了一台虚拟机?教你如何玩转它...