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

在自己电脑C:\Users\hanmm\.m2\下的setting.xml。

1.服务器配置

<server>
<id>nexus-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>

id:与Maven想要连接上的repository/mirror中的id元素相匹配。

username,password:这两个元素成对出现,表示连接这个server需要验证username和password。

这里使用两个服务器配置,分别对应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>

Maven项目使用Nexus作为远程仓库的settings.xml配置的更多相关文章

  1. 让maven项目使用nexus作为远程仓库

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

  2. 【Maven学习】Nexus OSS私服仓库的安装和配置

    背景 公司的代码依赖是通过Maven进行管理的,而Maven的私库我们使用的是Nexus,目前使用的版本是Nexus Repository Manager OSS 2.12.1. 但是由于之前我们搭建 ...

  3. 配置maven访问nexus,配置项目pom.xml以发布maven项目到nexus中

    maven访问nexus有三种配置方法,分别为: 项目pom.xml,优先级最高: user的settings.xml,优先级中,未在pom.xml中配置repository标签,则使用这个配置: m ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Pipeline 模型

    解决的问题 解决并发效率问题,将任务拆分成流水线,然后多线程并发执行,比之单线程执行快. 案例 CPU 流水线 Tomcat 容器 Structs

  2. indexedDB添加,删除,获取,修改

    [toc] 在chrome(版本 70.0.3538.110)测试正常 编写涉及:css, html, js 在线演示codepen html代码 <h1>indexedDB</h1 ...

  3. 重学计算机组成原理(五)- "旋转跳跃"的指令实现

    CPU执行的也不只是一条指令,一般一个程序包含很多条指令 因为有if-else.for这样的条件和循环存在,这些指令也不会一路平直执行下去. 一个计算机程序是怎么被分解成一条条指令来执行的呢 1 CP ...

  4. 《机器学习基石》---VC维

    1 VC维的定义 VC维其实就是第一个break point的之前的样本容量.标准定义是:对一个假设空间,如果存在N个样本能够被假设空间中的h按所有可能的2的N次方种形式分开,则称该假设空间能够把N个 ...

  5. 用 程序 解决 windows防火墙 的 弹窗 问题

    今天用户反馈了一个问题,运行程序弹了个框 这个只有程序第一次运行会出来,之后就不会了. 当然改个程序名字,又会弹出来. 强烈怀疑是写到了注册表,果然被我找到了. “HKEY_LOCAL_MACHINE ...

  6. 003——Netty之Buffer、Channel以及多路复用器Selector

    Buffer 1.缓冲区类型 2.缓冲区定义 (1)Buffer是一个对象,其中包含写入与读出的数据.是新IO与原IO的重要区别.任何情况下访问NIO中的数据都需要通过缓存区进行操作. (2)Buff ...

  7. (十二)c#Winform自定义控件-分页控件

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  8. MySQL主从配置图文详解

    #环境配置#master IP:192.168.46.137 slave IP:192.168.46.138 database:v1 1.在两台机器,分别安装mysql数据库,分别添加远程连接权限 2 ...

  9. Spring中的属性编辑器的使用

    Spring中的属性编辑器的使用 转载自 http://blog.sina.com.cn/s/blog_59ca2c2a0100jxwh.html Struts中用一个类型转换器,在Spring中也有 ...

  10. JVM内存机制与垃圾收集器总结

    本文目录 1. JVM内存组成结构 2. JVM内存回收 3. 垃圾收集器与算法 4. jdk1.6中class文件结构 5. jdk1.6 1.7 1.8比较 1. JVM内存组成结构 JVM栈由堆 ...