码迷,mamicode.com
首页 > 其他好文 > 详细

在Maven中设置Nexus私有服务为中央工厂

时间:2016-04-02 22:47:13      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

 

在Maven中设置Nexus私有服务为中央工厂(repository)

技术分享 分类:
 

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>

 

第四种方式就是我们推荐的一种方式

 

在Maven中设置Nexus私有服务为中央工厂

标签:

原文地址:http://www.cnblogs.com/developer-ios/p/5348465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!