在Maven中设置Nexus私有服务为中央工厂
2016-04-02 22:15
246 查看
在Maven中设置Nexus私有服务为中央工厂(repository)
2015-12-12 17:45 168人阅读 评论(0) 收藏 举报分类:
Maven(17)
版权声明:本文为博主原创文章,未经博主允许不得转载。
nexus中的仓库列表
第一种方式:
<repositories>
<repository>
<id>nexus</id>
<name>nexus Repository</name>
<url>http://localhost:8081/nexus/content/repositories/central/</url>
</repository>
</repositories>
这种方式,Maven仅仅只会在nexus中的central中央工厂进行下载,而我们希望我们开发的releases、snapshots工厂都能下载
而这种方式会增加配置的复杂度,并且增加了配置文件的冗余,而没增加一个都会去添加,这种方式不推荐使用
第二种方式:
为解决第一种方式,在nexus中提供了另外一种方式仓库为:Public Repositories 类型为group Repository Path为:http://localhost:8081/nexus/content/groups/public/
的方式
在pom.xml中我们只需要将url地址更改成它的地址即可,用了这个工厂就相当于用了Releases、Snapshots、3rd party 、Central这几个工厂
<repositories>
<repository>
<id>nexus</id>
<name>nexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
设置了之后,当我们有新的依赖,它就回去nexus中的仓库中去下载
第二种方式,当还一个模块的时候还的配置,这样就不太方便,在企业开发中,我们需要设置一个共有的,因此第三中方式就来了
第三种方式
将自己设置的工厂中的settings.xml进行配置
<profiles>
<profile>
<id>nexusRepository</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus is Repository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!-- 默认就是true -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 默认是是false,需手动打开 设置为true -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 这里必须激活profile 才能生效 -->
<activeProfiles>
<activeProfile>nexusRepository</activeProfile>
</activeProfiles>
这样默认也是从nexus repository下载
第三种方式在nexus服务器停止的了,maven有会从maven的中央工厂mvnrepository进行下载,这是因为,Maven项目首先回去nexus中去找,当它发现nexus服务停止这个时候它就回去找Maven的工厂
在Maven的安装包中的lib中的maven-model-builder-3.3.9.jar中的pom.xml,起配置如下
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
问题就是当我们发现Nexus服务停止了就不能下载,而只能从Nexus中下载,不允许去Maven中下载这就需要第四种方式
第四种方式:配置镜像
配置如下
<mirrors>
<mirror>
<id>mirrorNexusId</id>
<!-- *号代表所有工厂镜像 ,当Maven进来之后,不管什么工厂都回去找URL的地址去下载 -->
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<!-- 这里的工厂配置,是Maven中的,起snapshots是false,我们可以通过这种方式将其激活,就可以访问中央工厂中snapshots -->
<profiles>
<profile>
<id>nexusRepository</id>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 这里必须激活profile 才能生效 -->
<activeProfiles>
<activeProfile>nexusRepository</activeProfile>
</activeProfiles>
第四种方式就是我们推荐的一种方式
相关文章推荐
- [C#]textbox获取光标
- 有一种服务称为MaaS
- spark-submit动态提交的办法(SparkLauncher实战)
- Android网络图片加载缓存处理库的使用
- 5.2 高精度运算
- 自定义ScrollView+自定义滚动条
- 用switch语句制作菜单
- ACM输入问题以及矩阵最大路径累加和
- 常见数据库面试题目
- ARM-RTC的简单使用
- uboot.2016.03 在mini2440上norfalsh启动
- 用git写书
- jdk+tomcat+eclipse配置
- 电子小制作:一个家庭常见物理量显示装置
- 学习计划
- 数据类型TextView中添入int型的错误
- PE 001~010
- hibernate实体映射的一些可选优化/配置
- 软件工程第四个程序:结对项目 —— 电梯调度问题(分析)
- thinkphp3.2.3笔记-验证码