让maven项目使用nexus作为远程仓库有两种方式,第一种是在项目的pom.xml中进行更改,让单个项目使用nexus仓库;另一种是通过修改maven的配置文件settings.xml进行更改,让所有项目都使用nexus仓库。

进入maven安装目录的conf文件夹打开,修改settings.xml文件。

1.服务器配置

  1. <server>
  2. <id>nexus-releases</id>
  3. <username>admin</username>
  4. <password>admin123</password>
  5. </server>
  6. <server>
  7. <id>nexus-snapshots</id>
  8. <username>admin</username>
  9. <password>admin123</password>
  10. </server>
  11. </servers>

id:这是Server的ID(不是登录进来的user),与Maven想要连接上的repository/mirror中的id元素相匹配。

username,password:这两个元素成对出现,表示连接这个server需要验证username和password。在nexus中,默认管理员用户名为admin,密码为admin123。

这里使用两个服务器配置,分别对应release和snapshot。

2.镜像

 
  1. <mirrors>
  2. <mirror>
  3. <id>nexus-releases</id>
  4. <mirrorOf>*</mirrorOf>
  5. <url>http://localhost:8081/nexus/content/groups/public</url>
  6. </mirror>
  7. <mirror>
  8. <id>nexus-snapshots</id>
  9. <mirrorOf>*</mirrorOf>
  10. <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
  11. </mirror>
  12. </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.配置

  1. <profiles>
  2. <profile>
  3. <id>nexus</id>
  4. <repositories>
  5. <repository>
  6. <id>nexus-releases</id>
  7. <url>http://nexus-releases</url>
  8. <releases><enabled>true</enabled></releases>
  9. <snapshots><enabled>true</enabled></snapshots>
  10. </repository>
  11. <repository>
  12. <id>nexus-snapshots</id>
  13. <url>http://nexus-snapshots</url>
  14. <releases><enabled>true</enabled></releases>
  15. <snapshots><enabled>true</enabled></snapshots>
  16. </repository>
  17. </repositories>
  18. <pluginRepositories>
  19. <pluginRepository>
  20. <id>nexus-releases</id>
  21. <url>http://nexus-releases</url>
  22. <releases><enabled>true</enabled></releases>
  23. <snapshots><enabled>true</enabled></snapshots>
  24. </pluginRepository>
  25. <pluginRepository>
  26. <id>nexus-snapshots</id>
  27. <url>http://nexus-snapshots</url>
  28. <releases><enabled>true</enabled></releases>
  29. <snapshots><enabled>true</enabled></snapshots>
  30. </pluginRepository>
  31. </pluginRepositories>
  32. </profile>
  33. </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.当前启用配置

  1. <activeProfiles>
  2. <activeProfile>nexus</activeProfile>
  3. </activeProfiles>

用以规定当前启用的配置,将对应profile的ID加入到这一项即可使profile生效。

 

5.完整配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  5. <pluginGroups></pluginGroups>
  6. <proxies></proxies>
  7. <servers>
  8. <server>
  9. <id>nexus-releases</id>
  10. <username>admin</username>
  11. <password>admin123</password>
  12. </server>
  13. <server>
  14. <id>nexus-snapshots</id>
  15. <username>admin</username>
  16. <password>admin123</password>
  17. </server>
  18. </servers>
  19. <mirrors>
  20. <mirror>
  21. <id>nexus-releases</id>
  22. <mirrorOf>*</mirrorOf>
  23. <url>http://localhost:8081/nexus/content/groups/public</url>
  24. </mirror>
  25. <mirror>
  26. <id>nexus-snapshots</id>
  27. <mirrorOf>*</mirrorOf>
  28. <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
  29. </mirror>
  30. </mirrors>
  31. <profiles>
  32. <profile>
  33. <id>nexus</id>
  34. <repositories>
  35. <repository>
  36. <id>nexus-releases</id>
  37. <url>http://nexus-releases</url>
  38. <releases><enabled>true</enabled></releases>
  39. <snapshots><enabled>true</enabled></snapshots>
  40. </repository>
  41. <repository>
  42. <id>nexus-snapshots</id>
  43. <url>http://nexus-snapshots</url>
  44. <releases><enabled>true</enabled></releases>
  45. <snapshots><enabled>true</enabled></snapshots>
  46. </repository>
  47. </repositories>
  48. <pluginRepositories>
  49. <pluginRepository>
  50. <id>nexus-releases</id>
  51. <url>http://nexus-releases</url>
  52. <releases><enabled>true</enabled></releases>
  53. <snapshots><enabled>true</enabled></snapshots>
  54. </pluginRepository>
  55. <pluginRepository>
  56. <id>nexus-snapshots</id>
  57. <url>http://nexus-snapshots</url>
  58. <releases><enabled>true</enabled></releases>
  59. <snapshots><enabled>true</enabled></snapshots>
  60. </pluginRepository>
  61. </pluginRepositories>
  62. </profile>
  63. </profiles>
  64. <activeProfiles>
  65. <activeProfile>nexus</activeProfile>
  66. </activeProfiles>
  67. </settings>

让maven项目使用nexus作为远程仓库的更多相关文章

  1. Maven项目使用Nexus作为远程仓库的settings.xml配置

    Maven项目使用Nexus作为远程仓库的settings.xml配置(转) 在自己电脑C:\Users\hanmm\.m2\下的setting.xml. 1.服务器配置 <server> ...

  2. maven 添加jar到中央/远程仓库

    maven 添加jar到中央/远程仓库 开源中国 发表于 2014-08-23 00:08:00 commond: mvn deploy:deploy-file -DgroupId=com.tima. ...

  3. 【Maven学习】Nexus OSS私服仓库的备份与迁移

    背景 在上一篇博客 [Maven学习]Nexus OSS私服仓库的安装和配置 中,我们已经在机房搭建好了新的Nexus OSS私服仓库.下面是两个版本的Nexus OSS私服仓库的对比图. 老的Nex ...

  4. 3.发布Maven项目到nexus中

    1.在pom.xml文件中配置需要发布的工厂 如果想把项目发布到nexus中,需要在pom.xml中配置releases和snapshots版本发布的具体repository <distribu ...

  5. 项目管理---git----快速使用git笔记(五)------本地项目代码提交到远程仓库---新建项目

    上一篇我们已经知道了怎么从远程仓库获取项目文件代码. 项目管理---git----快速使用git笔记(四)------远程项目代码的首次获取 git还有一种使用场景是 我本来在电脑里就有一个项目,现在 ...

  6. 使用tortoise git将一个现有项目推送到远程仓库

    一.安装文件: 1.git https://git-scm.com/downloads 2.tortoise git https://tortoisegit.org/download/ 二.将一个现有 ...

  7. git 本地项目推送至远程仓库

    1 在本地文件夹下创建一个 Git 仓库(如test目录下) git init 2 此时test文件夹即是你的maste主分支,你可以在改文件夹下写自己的项目 3 将test文件夹下的内容提交至暂存区 ...

  8. 使用git命令将本地项目推送到远程仓库

    将本地项目推送到远程仓库 这里先放一张图, 有助于理解git命令 1. 在GitHub上新建一个仓库 注意不要勾选自动生成README.md文件, 否则会产生某些问题, README.md文件到时可以 ...

  9. git的详细使用,项目创建到同步远程仓库,版本回退,忽略文件,分支创建,分支合并,分支名称修改,冲突解决,项目迁移

    注意:此处省略git的安装 1..git的工作流程示意图: 2.本地仓库的初始化: 2.1 创建一个文件夹,如我创建的是:D:\gitdemo\shop 2.2 进入shop目录,鼠标右键,打开git ...

随机推荐

  1. 最好使用%f输出浮点数据,acm

    今天做题的时候发现使用%lf输出的时候总是wrong,而一旦改成%f就ac了,询问学长后知道,不要用%lf输出,浮点都用%f 然而我还是有疑惑,如果%f容不下输出的数据怎么办呢? 于是我就去百度 原来 ...

  2. 结对项目 https://github.com/quchengyu/jiedui/tree/quchengyu-patch-1

    所选项目名称:文本替换      结对人:傅艺伟 github地址 : https://github.com/quchengyu/jiedui/tree/quchengyu-patch-1 用一个新字 ...

  3. 第二个spring, 第7天

    陈志棚:成绩的统筹 李天麟:界面音乐 徐侃:代码算法 代码初步已经完成.还差最后一步整合.附上最后一张截图

  4. 开源RabbitMQ操作组件

    开源RabbitMQ操作组件 对于目前大多的.NET项目,其实使用的技术栈都是差不多,估计现在很少用控件开发项目的了,毕竟一大堆问题.对.NET的项目,目前比较适合的架构ASP.NET MVC,ASP ...

  5. PAT 1071 小赌怡情

    https://pintia.cn/problem-sets/994805260223102976/problems/994805264312549376 常言道“小赌怡情”.这是一个很简单的小游戏: ...

  6. Trouble shooting(问题解决):centos 7 gnome show someting has gone wrong.

    centos 7 升级 内核 3.10,startx启动不了了.进界面也是oh,no!someting has gone wrong . 参见帖子:http://bbs.csdn.net/topics ...

  7. 关于windows内存的一些简单看法

    1. 公司的产品有一个检查windows操作系统的功能,验证是否满足 只能客户端 的运行需求: 这里面的可用虚拟内存是128T 感觉非常奇怪了. 然后自己想了下128T 是 2的 47次方 猜想是不是 ...

  8. poj 3694 Network(割边+lca)

    题目链接:http://poj.org/problem?id=3694 题意:一个无向图中本来有若干条桥,有Q个操作,每次加一条边(u,v),每次操作后输出桥的数目. 分析:通常的做法是:先求出该无向 ...

  9. charles代理以及关于其抓取https信息的操作

    一直没有写一篇关于charles的文章来记录,但是发现偶尔还是会忘记,所以还是记一下,查起来比较方便. 首先在安装了charles之后默认的本地代理地址是 127.0.0.1:8888这个地址.如果希 ...

  10. Linux基础学习(8)--权限管理

    第八章——权限管理 一.ACL权限 1.ACL权限简介与开启: (1)ACL权限简介: (2)查看分区ACL权限是否开启: (3)临时开启分区ACL权限: (4)永久开启分区ACL权限: 2.查看与设 ...