maven仓库使用

maven镜像仓库

1.国内maven镜像仓库

阿里云镜像

<mirrors>
<mirror>
  <id>aliyun</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</ur>
  <mirrorOf>central</mirrorOf>        
</mirror>
</mirrors>

开源中国镜像

<mirror>
<id>OSChina</id>
<name>OSChina Central</name>                                   
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>

repo2 maven仓库

<mirror>  
<id>repo2</id>  
<mirrorOf>central</mirrorOf>  
<name>Human Readable Name for this Mirror.</name>  
<url>http://repo2.maven.org/maven2/</url>  
</mirror>

net-cn 镜像

<mirror>  
<id>net-cn</id>  
<mirrorOf>central</mirrorOf>  
<name>Human Readable Name for this Mirror.</name>  
<url>http://maven.net.cn/content/groups/public/</url>   
</mirror>

uk镜像

<mirror>  
<id>uk</id>  
<mirrorOf>central</mirrorOf>  
<name>Human Readable Name for this Mirror.</name>  
<url>http://uk.maven.org/maven2/</url>  
</mirror>

ibiblio 镜像

<mirror>  
<id>ibiblio</id>  
<mirrorOf>central</mirrorOf>  
<name>Human Readable Name for this Mirror.</name>  
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>  
</mirror>

jboss镜像

<mirror>  
<id>jboss-public-repository-group</id>  
<mirrorOf>central</mirrorOf>  
<name>JBoss Public Repository Group</name>  
<url>http://repository.jboss.org/nexus/content/groups/public/url>  
</mirror>
2.添加maven仓库
2.1在POM中配置远程仓库
<repositories>  
<repository>  
  <id>my-repo</id>  
  <name>my repository</name>  
  <url>http://localhost:8080/artifactory/my-repo/</url>  
  <releases>  
    <enabled>true</enabled>  
  </releases>  
  <snapshots>  
    <enabled>true</enabled>  
  </snapshots>  
</repository>  
</repositories>  

 <pluginRepositories>  
<pluginRepository>  
  <id>my-repo</id>  
  <name>my repository</name>  
  <url>http://localhost:8080/artifactory/my-repo/</url>  
  <releases>  
    <enabled>true</enabled>  
  </releases>  
  <snapshots>  
    <enabled>true</enabled>  
  </snapshots>  
</pluginRepository>  
<pluginRepository>  
  <name>oss.sonatype.org</name>  
  <id>oss.sonatype.org</id>  
  <url>http://oss.sonatype.org/content/groups/public</url>  
</pluginRepository>  
</pluginRepositories>  
2.2在settings.xml中配置远程仓库

除了在pox.xml配置仓库,setting文件可以作为一个全局的配置,但并不是简单的将POM中的元素复制到settings.xml中就可以,setting.xml不直接支持 这两个元素。但我们还是有一个并不复杂的解决方案,就是利用profile,如下:
[html] view plain copy 在CODE上查看代码片派生到我的代码片

<settings>    
...    
<profiles>    
    <profile>    
        <id>dev</id>    
    <!-- repositories and pluginRepositories here-->    
</profile>    
</profiles>    
<activeProfiles>    
    <activeProfile>dev</activeProfile>    
</activeProfiles>    
    ...    
</settings>    

这里我们定义一个id为dev的profile,将所有repositories以及pluginRepositories元素放到这个profile中,然后,使用元素自动激活该profile。这样,你就不用再为每个POM重复配置仓库。

原文地址:https://www.cnblogs.com/weiguo21/p/6165215.html