`

Archiva与Nexus配置

 
阅读更多

 

从08年初开始使用Maven2至今,已经两年有半。期间我们一直在使用的Maven2 Repository管理工具是Apache的Archiva。在使用Archiva的过程中,遇到一些问题没有及时解决,主要有:

  1. 有些artifact不会通过配置的Archiva服务器下载;
  2. 有些artifact下载的压缩包有问题,而系统会认为下载成功,不会每次从Archiva再次下载正确的artifact。

由于没有时间对Archiva配置进行细致的研究,对于这些问题我们并没有解决,而是采用替代方案:

  1. 让那些artifact绕过Archiva服务器下载(反正绕过它也没遇到更到问题);
  2. 写脚本扫描并删除有问题的压缩包文件(要同时删除本地文件,以及Archiva服务器上的缓存文件),再次更新项目的Maven依赖后,会自动再次下载。

最近由于网络问题,一些artifact始终下载不了,所以下定决心去研究一下Archiva的配置。过程中也下载了一份Nexus并做了简单的对比,下面是对Archiva和Nexus配置的一些记载。

我理解的Archiva服务器工作方式:

  1. 当本地的Maven项目请求一个artifact时,会先去本地的Repository中查找;
  2. 若没有找到符合的artifact,则会向Archiva服务器请求该artifact,这是由于本地设置(~/.m2/settings.xml或%MAVEN_HOME%/conf/settings.xml中设置)了以Archiva服务器作为所有Repository的mirror
  3. Archiva服务器的Managed Repository会接收这个请求,并从Managed Repository中寻找符合条件的artifact;
  4. 若没有找到符合条件的artifact,会从设置了proxy connector的Remote Repository中寻找符合条件的artifact,如果找到则从Remote Repository中下载一份到Managed Repository中,并回应客户请求(发自我们本地的请求);
  5. 如果没有找到符合条件的artifact,Archiva服务器则返回404信息,交给本地处理(本地会再去配置的Repository列表中去查找)。
archiva reference 写道
A proxy connector is used to link a managed repository (stored on the Archiva machine) to a remote repository (accessed via a URL). This will mean that when a request is received by the managed repository, the connector is consulted to decide whether it should request the resource from the remote repository (and potentially cache the result locally for future requests).
 
配置Archiva mirror所有Repository的代码(~/.m2/settings.xml或%MAVEN_HOME%/conf/settings.xml中):
Xml代码   收藏代码
  1. <mirrors>  
  2.     <mirror>  
  3.         <id>archiva.default</id>  
  4.         <name>archiva.default</name>  
  5.         <url>http://localhost:8088/archiva/repository/internal</url>  
  6.         <mirrorOf>*</mirrorOf>  
  7.     </mirror>  
  8.     <mirror>  
  9.         <id>archiva.apache.snapshots</id>  
  10.         <name>archiva.apache.snapshots</name>  
  11.         <url>http://localhost:8088/archiva/repository/snapshots</url>  
  12.         <mirrorOf>apache.snapshots</mirrorOf>  
  13.     </mirror>  
  14. </mirrors>  

注意事项:
  1. 要保证Archiva找到符合的artifact,必须保证在Archiva中配置的Remote Repository中能够找到该artifact;
  2. 要想Archiva能够从Remote Repository中去找artifact,必须要对该Remote Repository设置一个proxy connector,否则Archiva从本地找不到artifact时不会去没有配置proxy connector的Remote Repository中找,这就是我们之前遇到的问题1的根源;
我理解的Nexus服务器工作方式:
  1. 当本地的Maven项目请求一个artifact时,会先去本地的Repository中查找;
  2. 若没有找到符合的artifact,则会从本地配置的Repository列表中按顺序去查找;
  3. 若当前查找的Repository是设置~/.m2/settings.xml或%MAVEN_HOME%/conf/settings.xml中设置为被Nexus mirror的,则向Nexus请求该artifact;
  4. Nexus接收请求后,会到相应的Repository中查找本地是否有该artifact的缓存,若有则返回给客户;
  5. 若没有,则从Repository中查找是否有该artifact,若有则从远处Repository下载一份在本地缓存;
  6. 若没有则返回客户,客户端会继续查找下一个Repository。
nexus reference 写道
When you encounter a project which contains a custom repository element in a pom.xml add this repository to Nexus as a new proxy repository and then add the new proxy repository to the public group.
 
配置Nexus mirror所有Repository的代码~/.m2/settings.xml或%MAVEN_HOME%/conf/settings.xml中):
Xml代码   收藏代码
  1. <mirrors>  
  2.     <mirror>  
  3.         <!--This sends everything else to /public -->  
  4.         <id>nexus</id>  
  5.         <mirrorOf>*</mirrorOf>  
  6.         <url>http://localhost:8081/nexus/content/groups/public</url>  
  7.     </mirror>  
  8. </mirrors>  
  9. <profiles>  
  10.     <profile>  
  11.         <id>nexus</id>  
  12.         <!-- Enable snapshots for the built in central repo to direct all requests to nexus via the mirror -->  
  13.         <repositories>  
  14.             <!-- Maven Central -->  
  15.             <repository>  
  16.                 <id>central</id>  
  17.                 <id>central</id>  
  18.                 <name>Maven Central</name>  
  19.                 <url>http://repo1.maven.org/maven2/</url>  
  20.                 <snapshots><enabled>false</enabled></snapshots>  
  21.             </repository>  
  22.   
  23.             <!-- Apache Snapshots -->  
  24.             <repository>  
  25.                 <id>apache-snapshots</id>  
  26.                 <name>Apache Snapshots</name>  
  27.                 <url>http://repository.apache.org/snapshots/</url>  
  28.                 <snapshots><enabled>true</enabled></snapshots>  
  29.             </repository>  
  30.   
  31.             <!-- Codehaus Snapshots -->  
  32.             <repository>  
  33.                 <id>codehaus-snapshots</id>  
  34.                 <name>Codehaus Snapshots</name>  
  35.                 <url>http://nexus.codehaus.org/snapshots/</url>  
  36.                 <snapshots><enabled>true</enabled></snapshots>  
  37.             </repository>  
  38.   
  39.             <!-- java.net - Maven 2 -->  
  40.             <repository>  
  41.                 <id>java.net-m2</id>  
  42.                 <name>java.net - Maven 2</name>  
  43.                 <url>http://download.java.net/maven/2/</url>  
  44.                 <snapshots><enabled>false</enabled></snapshots>  
  45.             </repository>  
  46.   
  47.             <!-- Google Code -->  
  48.             <repository>  
  49.                 <id>google</id>  
  50.                 <name>Google Code</name>  
  51.                 <url>http://google-maven-repository.googlecode.com/svn/repository/</url>  
  52.   
  53.             </repository>  
  54.   
  55.             <!-- jahia -->  
  56.             <repository>  
  57.                 <id>jahia</id>  
  58.                 <name>jahia</name>  
  59.                 <url>http://maven.jahia.org/maven2/</url>  
  60.                 <snapshots><enabled>false</enabled></snapshots>  
  61.             </repository>  
  62.   
  63.             <!-- SpringSide Additional Repository -->  
  64.             <repository>  
  65.                 <id>springside</id>  
  66.                 <name>SpringSide Additional Repository</name>  
  67.                 <url>http://springside.googlecode.com/svn/repository/</url>  
  68.                 <snapshots><enabled>false</enabled></snapshots>  
  69.             </repository>  
  70.   
  71.             <!-- Jboss Repository -->  
  72.             <repository>  
  73.                 <id>jboss</id>  
  74.                 <name>Jboss Repository</name>  
  75.                 <url>http://repository.jboss.com/maven2/</url>  
  76.                 <snapshots><enabled>false</enabled></snapshots>  
  77.             </repository>  
  78.         </repositories>  
  79.     </profile>  
  80. </profiles>  
  81.   
  82. <activeProfiles>  
  83.     <!--make the profile active all the time -->  
  84.     <activeProfile>nexus</activeProfile>  
  85. </activeProfiles>  
 
注意事项:
  1. 要保证Nexus去管理所有的artifact,必须设置Nexus mirror你项目中配置的所有Repository;
  2. 要在Nexus服务器中配置你mirror的所有Repository;

 

最后,关于问题2,应该是proxy connector中参数设置问题,只要把每个proxy connector的Checksum设置为fail,问题应该会自然解决。(之前配置的两个proxy connector的Checksum设置有问题,故有问题2发生;目前已更改配置,但是否解决问题仍需进一步跟踪)

 

参考地址:http://casheen.iteye.com/blog/730295

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics