Maven2中snapshot快照库的使用

来源:互联网 发布:中国网络拍卖平台首页 编辑:程序博客网 时间:2024/06/05 15:22
[转载声明] 转载时必须标注:本文来源于铁木箱子的博客http://www.mzone.cc
[本文地址] 本文永久地址是:http://www.mzone.cc/article/654.html

      之前有过几篇文章介绍了mavven中release和snapshot库的作用,如下(不太了解的可以参考看一下):

      1、maven2中snapshot快照库和release发布库的应用

      2、maven中snapshot快照库和release发布库的区别和作用

      另外,今天在使用snapshot快照库时遇到一个问题,我一个构件的发布配置如下(在构件的pom文件中):

  1. <modelVersion>4.0.0</modelVersion>
  2. <groupId>cc.mzone</groupId>
  3. <artifactId>workflow</artifactId>
  4. <version>0.1-SNAPSHOT</version>
  5. <packaging>jar</packaging>
  6. <distributionManagement>
  7. <repository>
  8. <id>kt</id>
  9. <url>http://192.168.1.112/nexus/content/repositories/kt</url>
  10. </repository>
  11. <snapshotRepository>
  12. <id>kt-snapshot</id>
  13. <url>http://192.168.1.112/nexus/content/repositories/kt-snapshot</url>
  14. <uniqueVersion>true</uniqueVersion>
  15. </snapshotRepository>
  16. </distributionManagement>

      这个是构件的发布配置,其中snapshot快照库中使用了uniqueVersion为true,这个表明每次发布都会在服务器上留下一个新版本(加上时间后缀的版本)。这个true和false不影响快照库,只是是否节省服务器空间的问题。在通过mvn deploy发布到服务器后,在依赖该构件的项目的pom文件中写上依赖:

  1. <dependency>
  2. <groupId>cc.mzone</groupId>
  3. <artifactId>workflow</artifactId>
  4. <version>0.1-SNAPSHOT</version>
  5. </dependency>

      然后在该项目中执行:mvn eclipse:eclipse进行其依赖构件的下载,结果却发现提示如下:

  1. [WARNING] An error occurred during dependency resolution.
  2. Failed to retrieve cc.mzone:workflow-0.1-SNAPSHOT
  3. Caused by: Unable to download the artifact from any repository
  4. Try downloading the file manually from the project website.

      刚开始不太清楚原因,经过查证比对,发现是因为项目没有开启snapshot快照库的缘故!知道了原因,解决就好办了,有两种方法可以解决:

1、第一种方法是在项目的pom文件中进行配置,如下

  1. <repositories>
  2. <repository>
  3. <id>cc-mzone-nexus</id>
  4. <name>MZONE</name>
  5. <url>http://192.168.1.112/nexus/content/groups/public/</url>
  6. <snapshots>
  7. <enabled>true</enabled>
  8. <updatePolicy>interval:5</updatePolicy>
  9. </snapshots>
  10. </repository>
  11. </repositories>

2、第二种方法是在maven的配置文件(conf/settings.xml)中进行配置,如下

  1. <profiles>
  2. <profile>
  3. <id>cc-mzone-profile</id>
  4. <repositories>
  5. <repository>
  6. <id>cc-mzone-nexus</id>
  7. <name>MZONE</name>
  8. <url>http://192.168.1.112/nexus/content/groups/public/</url>
  9. <releases>
  10. <enabled>true</enabled>
  11. </releases>
  12. <snapshots>
  13. <enabled>true</enabled>
  14. <updatePolicy>interval:10</updatePolicy>
  15. </snapshots>
  16. </repository>
  17. </repositories>
  18. </profile>
  19. </profiles>
  20. <activeProfiles>
  21. <activeProfile>cc-mzone-profile</activeProfile>
  22. </activeProfiles>

      以上两种方式都是打开snapshot快照库,允许快照库生效(重要就是snapshot中enabled要设置为true),第一种是项目级别的,第二种是全局的。出现的问题当然主要还是默认snapshot快照库是没有生效导致的,如此配置即可解决

原创粉丝点击