在settings.xml中配置远程仓库
我们知道了如何在POM中配置远程仓库,但考虑这样的情况:在一个公司内部,同时进行这3个项目,而且以后随着这几个项目的结束,越来越多的项目会开始;同时,公司内部建立一个Maven仓库。我们统一为所有这些项目配置该仓库,于是不得不为每个项目提供同样的配置。问题出现了,这是重复 !
其实我们可以做到只配置一次,在哪里配置呢?就是settings.xml。
不过事情没有那么简单,不是简单的将POM中的<repositories>及<pluginRepositories>元素复制到settings.xml中就可以,setting.xml不直接支持 这两个元素。但我们还是有一个并不复杂的解决方案,就是利用profile,如下:
- <settings>  
-   ...   
-   <profiles>  
-     <profile>  
-       <id>dev</id>  
-       
-     </profile>  
-   </profiles>  
-   <activeProfiles>  
-     <activeProfile>dev</activeProfile>  
-   </activeProfiles>  
-   ...   
- </settings>  
 
- <settings>  
-   ...  
-   <profiles>  
-     <profile>  
-       <id>dev</id>  
-       
-     </profile>  
-   </profiles>  
-   <activeProfiles>  
-     <activeProfile>dev</activeProfile>  
-   </activeProfiles>  
-   ...  
- </settings>  
 
这里我们定义一个id为dev的profile,将所有repositories以及pluginRepositories元素放到这个profile中,然后,使用<activeProfiles>元素自动激活该profile。这样,你就不用再为每个POM重复配置仓库。
使用profile为settings.xml添加仓库提供了一种用户全局范围的仓库配置。
 
镜像
如果你的地理位置附近有一个速度更快的central镜像,或者你想覆盖central仓库配置,或者你想为所有POM使用唯一的一个远程仓库(这个远程仓库代理的所有必要的其它仓库),你可以使用settings.xml中的mirror配置。
以下的mirror配置用maven.net.cn覆盖了Maven自带的central:
- <settings>  
- ...   
-   <mirrors>  
-     <mirror>  
-       <id>maven-net-cn</id>  
-       <name>Maven China Mirror</name>  
-       <url>http://maven.net.cn/content/groups/public/</url>  
-       <mirrorOf>central</mirrorOf>  
-     </mirror>  
-   </mirrors>  
- ...   
- </settings>  
 
- <settings>  
- ...  
-   <mirrors>  
-     <mirror>  
-       <id>maven-net-cn</id>  
-       <name>Maven China Mirror</name>  
-       <url>http://maven.net.cn/content/groups/public/</url>  
-       <mirrorOf>central</mirrorOf>  
-     </mirror>  
-   </mirrors>  
- ...  
- </settings>  
 
 
这里唯一需要解释的是<mirrorOf>,这里我们配置central的镜像,我们也可以配置一个所有仓库的镜像,以保证该镜像是Maven唯一使用的仓库:
- <settings>  
- ...   
-   <mirrors>  
-     <mirror>  
-       <id>my-org-repo</id>  
-       <name>Repository in My Orgnization</name>  
-       <url>http://192.168.1.100/maven2</url>  
-       <mirrorOf>*</mirrorOf>  
-     </mirror>  
-   </mirrors>  
- ...   
- </settings>  
 
- <settings>  
- ...  
-   <mirrors>  
-     <mirror>  
-       <id>my-org-repo</id>  
-       <name>Repository in My Orgnization</name>  
-       <url>http://192.168.1.100/maven2</url>  
-       <mirrorOf>*</mirrorOf>  
-     </mirror>  
-   </mirrors>  
- ...  
- </settings>  
 
关于更加高级的镜像配置,可以参考:http://maven.apache.org/guides/mini/guide-mirror-settings.html。
http://blog.csdn.net/joewolf/article/details/4876604
 
maven repository
原文:http://www.cnblogs.com/softidea/p/5914757.html